JSFiddle - React, Tailwind, and code Playground

JavaScript

var arr = [3,1,2];
var sorted_arr = arr.sort(function(a,b) {
  console.log("a, b = ", a, b);
  if (a < b) {
    return -1;
  }
  if (a > b) {
    return 1;
  }
  // a must be equal to b
  return 0;
});

console.log("sorted_arr: ", sorted_arr)

var mapped = arr.map(function(el, i) {
  return { index: i, value: el.toString().toLowerCase() };
})

mapped.sort(function(a, b) {
  console.log("map: ", a, b)
  if (a.value > b.value) {
    return 1;
  }
  if (a.value < b.value) {
    return -1;
  }
  return 0;
});

// container for the resulting order
var result = mapped.map(function(el){
  return arr[el.index];
});


console.log("result: ", result)