Classificação da matriz com base em outra matriz

function sort(initialArray, sortingArray){
  let newArr = [];
  for (let i = 0; i< initialArray.length; i++){
    newArr.push(initialArray[sortingArray.indexOf(i)])
  }
  return newArr
}

console.log(sort([1, 2, 3, 4, 5], [0, 2, 1, 4, 3]))

///////////////// OR ///////////////////////////////////
function sort(a, b) {
  return a.map((n,i)=>a[b.indexOf(i)])
}

///////////////// OR ///////////////////////////////////
function sort(initialArray, sortingArray) {
  const result = [];
  sortingArray.forEach((el, i) => result[el] = initialArray[i]);
  return result;
}
Ngoc Chau