Can someone help me understand how the .sort() method works on, for example, an array?
if I have array = [1, 5, 3, 10, 2, 7, 4], and I want to use array.sort((a, b) => a - b)), does my sort on the array keep running until there is no more a and b comparisons that return -1 or 1? Like, does it sort by comparing (1, 5) then (5, 3), sort, then (5, 10), then (10, 2)…and when done sorting through the array once (by starting my comparing at index 0 through the end of array) will result my array to be now [1, 3, 5, 2, 7, 4, 10]. As we can see, it’s still not sorted, so does my sort method work through my array again, and again, until there is no more sorting left to do?
Then what kind of sort is Javascrip’s .sort((a, b) => a - b))?
Also does anyone know a good youtube tutorial on how this sort with the callback function works?