I know I uploaded a similar question, but my intention is different here so this is not a duplicate question.
I want to sort an array based on another array of numbers. More specifically, if 1 is the nth element of the array of numbers, I want to rearrange the target array so that the nth element in the original array is the first element, and so on. For example;
//Case 1
const input = ["a", "b", "c", "d", "e"];
const order = [2, 4, 5, 1, 3];
intended_result: ["d", "a", "e", "b", "c"];
//Case 2
const input = ["a", "b", "c", "d", "e"];
const order = [3, 1, 4, 5, 2];
intended_result: ["b", "e", "a", "c", "d"];
What would be the Javascript code to do the above operation? Any suggestion?
Thanks a lot in advance!