I'm trying to grasp what's going on "under the hood" of the array.sort function in Javascript. Let's use the following example:
var myarray=[25, 8, 7, 41]
myarray.sort(function(a,{return a - b}) //Array now becomes [7, 8, 25, 41]
I know it might sound silly, but since the function takes two values -- a and b -- exactly which two values are being compared at any given time in the logic??
I understand the sorting "rules" in terms of <0, 0, and >0 re: sort order. I'm just wondering what, exactly is going on in the sort process in Javascript at each step of the function?
In other words, is the first step to set parameter a to 25 and b to 8 and do the subtraction, then 25 - 7, then 25 - 41? This is what is seemingly never explained in the examples I see. Is it a loop that's being performed with every possible iteration of elements in the array subtracting from each other in this case?
I'm wondering what is assigned to "a" and what to "b" at any given time while the function processes.
(I don't know why "B" shows up in the code capitalized - I tried to make it lower-case but it wouldn't take.)