Post

Gonna ask probably a stupid question. In the first sort you leave it blank, and it’s obviously alphabetical. In the second sort the function you pass in is a-b, what is that doing to the sort?

In JS, `Array.sort()` (and `.toSorted()`) coerce the values to a string, then do a unicode point value sort on that. Sometimes it's what you want, sometimes it isn't. Providing an explicit comparison function allows to change this behavior.

So in this case, a-b is comparing the first 2 numbers, 1-10, the answer is negative so 1 is placed first, then 10-21, again negative... so 10... and then 21-2, positive so 21 is larger so it places 2, 21. And we get 1,10,2,21 then it re-iterates until all are sorted? Is that the way to read it?