Finally Understanding How Array.sort(comparator) Works

James Kerr explains how the Array.sort() function actually works!


I’ve been the same as James for years:

In the past, I would just try b - a then try a - b and pick which one gave me the result I wanted. But now I have a mental model simple enough for me to remember.

Well, to be honest, this is that I ask GPT to work out for me these days 😬

Either way, James explains how the Array.sort() function works beautifully in this article. What a lovely looking blog too!

Check it out