I have an array of objects containing a particular structure. Then, I have an array (given by the user), which contains values in the order which the elements should be sorted. For simplicity, I'll give the following example:
const arrayOfObjects = [
{objectId: 1, color: 'Orange'},
{objectId: 2, color: 'Blue'},
{objectId: 3, color: 'White'},...
]
And the array given by the user for sorting:
['White', 'Orange', 'Blue']
Now my question is, how can I sort the first array, so that all objects with color white come first, then all the elements with orange color and then blue?
Note: The array will be given by the user, so cannot sort alphabetically.