I have an array with sizes like this:
var arr = [
'small',
'small',
'small',
'small',
...
'medium',
'medium',
'medium',
'medium',
...
'big',
'big',
...
];
I need to reorganize this array according to this order:
var order = ['small', 'small', 'medium', 'medium', 'big'];
So the result ends up being something like this:
var arr = [
'small',
'small',
'medium',
'medium',
'big',
'small',
'small',
'medium',
'medium',
'big'
...
];
I'm aware of other similar questions in SO but I couldn't find anything so far. I'm unsure how to approach this. I was thinking `sort` should do but what do I test for? It seems simple but I'm stuck, don't know where to begin. Any hints? I think you need to show an actual example of the array before and after. Right now I cannot see what makes the array split on the two sets you are showing in the output
以上就是Sorting an Array according to the order of another Array的详细内容,更多请关注web前端其它相关文章!