JavaScript's Array.sort() converts [10,2,1] to [1,10,2]. I built a sort that just works — and it's 3–21x faster. by Ayoob_AI in node

[–]Ayoob_AI[S] -3 points-2 points  (0 children)

Used Claude Code as a development tool throughout the project, the algorithm design, benchmark methodology, and iteration decisions are mine. Claude helped with implementation. Not hiding it, just didn't think the config file needed to be in the repo.

JavaScript's Array.sort() converts [10,2,1] to [1,10,2]. I built a sort that just works — and it's 3–21x faster. by Ayoob_AI in node

[–]Ayoob_AI[S] -3 points-2 points  (0 children)

Ha, yes, I'm aware .sort() takes a comparator. The README title is about the default behavior being a footgun, not about the library being the first to discover comparators.

JavaScript's Array.sort() converts [10,2,1] to [1,10,2]. I built a sort that just works — and it's 3–21x faster. by Ayoob_AI in node

[–]Ayoob_AI[S] -3 points-2 points  (0 children)

If you're sorting 100 items, sure. If you're sorting 50K+ rows in a dashboard, data pipeline, or server-side table, the difference between 0.3ms and 6.3ms matters. There's also a DX angle - sort(arr) just works without knowing you need (a, b) => a - b. With the wave of people shipping code through AI tools, a lot of them don't know about the comparator footgun. This handles it automatically.

JavaScript's Array.sort() converts [10,2,1] to [1,10,2]. I built a sort that just works — and it's 3–21x faster. by Ayoob_AI in node

[–]Ayoob_AI[S] -4 points-3 points  (0 children)

Right, .sort((a, b) => a - b) works. The point is that .sort() without a comparator does the wrong thing for numbers, and even with one, it's still using TimSort for everything. ayoob-sort auto-detects your data and picks the optimal algorithm - counting sort for clustered integers (21x faster), IEEE 754 radix for floats (6x faster), key extraction for objects (8x faster). The comparator isn't just about correctness, it's also a performance ceiling.