I'm wondering WHY when I sort items in the original array they show up in a weird order when processing but the result is correct.
Here's the code
var arr = [100, 8, 20, 12];
var x = 1;
console.log("Original Array = " + arr)
arr.sort(function(a,b){
console.log("Set " + x++) //for tracking purposes
console.log(a, b)
console.log("a-b = " + (a-b))
return a-b;
})
console.log(arr)
I've tried this on both SoloLearn and on Chrome to see if it had something to do with the browser itself but I get the same results
RESULT:
I want to understand why this behavior of sorting happens (a=8 and b=100...etc)
Any help or reference would be greatly appreciated.