I understand that the .sort function will sort from smallest to biggest.
But what is the a - b part actually doing?
If I remove or change it, the array no longer gets sorted.
I’ve tried adding in some logging to see what’s going on, but I don’t actually see a being reduced by b at any point?
Is there something more complex going on under the hood here?
function getIndexToIns(arr) {
const value = arr.sort((a, b) => {
console.log("a is " + a)
console.log("b is " + b)
return a - b});
console.log(value)
}
getIndexToIns([10, 20, 30, 50, 40]);