// We have this array of people, we want to get a new array sorted using the names in the order array below.
const collection = [{ name: 'carol' }, { name: 'stewie' }, { name: 'steve' }, { name: 'carl' }];
const order = ['carl', 'steve', 'carol', 'horseboy', 'stewie'];

// Just map over the order, and find the corresponding item in the collection.
const sortedCollection = order.map(orderName => collection.find(({ name }) => name === orderName ));

// To also remove undefindes, if the order element isn't found in the collection,
// do this (filter out any falsy elements)
sortedCollection.filter(x => x);

/*
  Notes on performance: The .find() function is probably O(N), which means that if you have a large collection
  and you run this sort thing often (very often) you should consider optimzing it.
*/