Can someone explain how subtracting one integer b
from a
returns an ordered array? E.g. I feel stupid for not understanding why this simple line solves this ..
var arr = [7, 2, 3, 100, 5, 6];
var sorted = arr.sort(function(a, b){
return a - b; // What makes this line sort the integers??
});
console.log(sorted); // [2, 3, 5, 6, 7, 100];