Y
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
kabacha
2128 days ago
Most popular programming language folks. You give it 3 numbers and it treats them as 3 strings of characters...
link
earthboundkid
2128 days ago
Wait, really?
BRB, just checking some codeā¦
link
astrod
2128 days ago
Yep, the sort method converts values to strings before comparing.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
link
zwaps
2128 days ago
I was confused why the author claims this doesn't work, then I saw JavaScript... ah
link