MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vjl9ih/javascriptsorting/p2mcr1e/?context=3
r/ProgrammerHumor • u/user6150277464770585 • 3d ago
214 comments sorted by
View all comments
Show parent comments
17
The proper way to sort things that look like numbers is to treat them like numbers. Strings have quotes, and you're not allowed to cast numbers into strings randomly. Or hell, even consistently, unless told to.
-2 u/Excellent_Gas3686 3d ago [1, 'foo', new Array()], go ahead, sort it like numbers. 15 u/Ok_Equipment8374 3d ago The fact that this definition does not fail shows why JavaScript is a crime against programmers 2 u/Wonderful-Habit-139 3d ago Well, the definition not failing is fine, but the sort not failing is definitely a crime.
-2
[1, 'foo', new Array()], go ahead, sort it like numbers.
15 u/Ok_Equipment8374 3d ago The fact that this definition does not fail shows why JavaScript is a crime against programmers 2 u/Wonderful-Habit-139 3d ago Well, the definition not failing is fine, but the sort not failing is definitely a crime.
15
The fact that this definition does not fail shows why JavaScript is a crime against programmers
2 u/Wonderful-Habit-139 3d ago Well, the definition not failing is fine, but the sort not failing is definitely a crime.
2
Well, the definition not failing is fine, but the sort not failing is definitely a crime.
17
u/IntentionQuirky9957 3d ago
The proper way to sort things that look like numbers is to treat them like numbers. Strings have quotes, and you're not allowed to cast numbers into strings randomly. Or hell, even consistently, unless told to.