I have noticed that the sorting occurs by converting each element to string and comparing the unicode numeric characters for that symbol.
MDN also has many more advanced details than that. I wanted to compare numbers so the solution on the web uses:
[...arr].sort((a,b)=>b-a))
The shallow copy is so we can keep the original array.
I can’t find though, how is the result of that operation influences the sorting. I guess something like this happens:
b-a larger than 0 then test with next element
a. when it changes sign place before that element
b-a less than 0 put it first
If 0 place there
But as I said before the sorting functions aren’t the easiest to set, I think. But do you think that is more or less how the function is used by Array.sort(fn) ?
UPDATE. Almost forgot - if you want learn more about sorting problems and get some practice at the same time, you can go to the code prep course of curriculum, there are bunch of challenges in algorithms section: some of them about sorting.
Yes, but they do not describe exactly how this is done. For example, when it sorts “b”, is it “b” always the same element and it goes trying “a” for each element in the array ? You could think that there are smarter ways to do it, or just different ones. And then moves to element indexOf(b)+1 and repeats?