4 ms·
Beware that in JavaScript, the language that this tweet is about, the sort function sorts alphabetically by default. [100, 10, 11].sort()[1] === 100
by dfabulich 6y 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
- earthboundkid 6y agoWait, really? BRB, just checking some code…
- astrod 6y agoYep, the sort method converts values to strings before comparing. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- kabacha 6y agoMost popular programming language folks. You give it 3 numbers and it treats them as 3 strings of characters...
- zwaps 6y agoI was confused why the author claims this doesn't work, then I saw JavaScript... ah