Hacker News new | ask | show | jobs
by dfabulich 2128 days ago
Beware that in JavaScript, the language that this tweet is about, the sort function sorts alphabetically by default.

    [100, 10, 11].sort()[1] === 100
3 comments

Most popular programming language folks. You give it 3 numbers and it treats them as 3 strings of characters...
Wait, really?

BRB, just checking some code…

Yep, the sort method converts values to strings before comparing. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I was confused why the author claims this doesn't work, then I saw JavaScript... ah