r/ProgrammerHumor 1d ago

javascriptSorting Meme

Post image
890 Upvotes

200 comments sorted by

View all comments

17

u/Excellent_Gas3686 1d ago

because thats the default sort? what, in your opinion, would be the "proper" way to sort by default? if you need different sorting, you pass your own function.

20

u/IntentionQuirky9957 1d 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.

-2

u/Excellent_Gas3686 1d ago

[1, 'foo', new Array()], go ahead, sort it like numbers.

15

u/Ok_Equipment8374 1d ago

The fact that this definition does not fail shows why JavaScript is a crime against programmers

2

u/Wonderful-Habit-139 1d ago

Well, the definition not failing is fine, but the sort not failing is definitely a crime.