This question is different to other questions on the topic of sorting a list based on the order of another list in the sense that the order list does not contain all the keys used in the list.
Say I have a list [a, b, c, d, e] and my order list [b, d, e].
Now I change my order list to [b, e, d]. Is there a relatively simple algorithm to resort the original list? Let's say it's not important whether the final ordering is [a, b, e, c, d] or [a, b, c, e, d], and the order list will always be a subset of the original list.
Edit: clearing up some questions about the final ordering, from my example: e was ordered to be between b and d, and in the sorted list it doesn't matter if e ends up adjacent to b or d. But for example, if due to this sorting a moved to after b - while a legal ordering - it's not desirable.
[b, e, d, a, c]legal? I am not 100% sure what you meanindexOf(e) < indexOf(d)so the final ordering it should reflect that. ButindexOf(a)is undefined so the ordering regardingashould stay the same.