javascript code simplification