logoalt Hacker News

zaphartoday at 11:46 AM1 replyview on HN

Why assume it is javascript? The article doesn't indicate the language anywhere that I can see.


Replies

gobdovantoday at 12:12 PM

Ok, let's say that it is not JS, but an untyped, closure-based programming language with a strikingly similar array and sort API to JS. Sadly, this comparator is still wrong for any sorting API that expects a general three-way comparison, because it does not handle equality as a separate case.

And to tie it down to the mathematics: if a sorting algorithm asks for a full comparison between a and b, and your function returns only a bool, you are conflating the "no" (a is before b) with the "no" (a is the same as b). This fails to represent equality as a separate case, which is exactly the kind of imprecision the author should be trying to teach against.

show 3 replies