I have an array with such shapes: var arr = [ 'Small', 'small', 'small', 'small', ... 'medium', 'medium', 'medium', 'medium', ... 'big', 'big', ...] ; I need to reconstruct this array according to this command: var command = ['short', 'small', ' Medium ',' medium ',' big ']; Then the result ends: var arr = ['short', 'small', 'medium', 'medium', ' Big ',' small ',' small ',' medium ',' medium ',' big '...]; I know about other such questions, but I could not find anything yet. I am uncertain about how to contact this. I was thinking sorting but for whom should I test? It sounds simple but I'm stuck, do not know where to start. Any signals? Just define scorer for your sort method. This is your code. Try it var init_arr = ['small', 'big', ...