rearrangement of things(javascript)