I have two arrays. The first array contains the sort order. The second array contains an arbitrary number of elements.
I have the property that all elements (by value) from the second array are guaranteed to be in the first array, and I only work with numbers.
A = [1,3,4,4,4,5,2,1,1,1,3,3]
Order = [3,1,2,4,5]
When I sort A, I would like the elements to appear in the order specified Order:
[3, 3, 3, 1, 1, 1, 1, 2, 4, 4, 4, 5]
Please note that duplicates are fair play. Elements in should not be changed, only reordered. How can i do this?
source
share