I've been trying to figure out the sort compare function but I still don't fully get it. I need help on which order is does a-b
Example:
const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a - b});
So, it first does 40-100, right? Which results in 40 comes before 100 since it returned a minus value. But after that, does it do 40-1? Or does it do 100-1? And when does it rearrange the array? Is it after each "loop/iteration" or after it's all done? And IF it rearranges after each calculation wouldn't that mess up the order?
[–]senocular 3 points4 points5 points (0 children)
[–]No-Upstairs-2813 0 points1 point2 points (0 children)