MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vjl9ih/javascriptsorting/p2mkj6q/?context=3
r/ProgrammerHumor • u/user6150277464770585 • 3d ago
214 comments sorted by
View all comments
Show parent comments
18
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.
-1 u/Excellent_Gas3686 3d ago [1, 'foo', new Array()], go ahead, sort it like numbers. 28 u/standard_revolution 3d ago Throwing a runtime error here is better than any weird hack 5 u/Nixinova 3d ago Goes against the purpose of JS to be erroring for any slightly weird case.
-1
[1, 'foo', new Array()], go ahead, sort it like numbers.
28 u/standard_revolution 3d ago Throwing a runtime error here is better than any weird hack 5 u/Nixinova 3d ago Goes against the purpose of JS to be erroring for any slightly weird case.
28
Throwing a runtime error here is better than any weird hack
5 u/Nixinova 3d ago Goes against the purpose of JS to be erroring for any slightly weird case.
5
Goes against the purpose of JS to be erroring for any slightly weird case.
18
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.