I have an array
const array = ['one', 'two', 'three'];
And an order array
const order = ['two', 'three', 'one'];
I sort array by order like that:
array.sort((a, b) => order.indexOf(a) - order.indexOf(b));
But if my order is shorter or longer than array's length then it's not working as I wish, it sorting it correctly but at the end of array.
How can I solve this?