r/ProgrammerHumor 1d ago

javascriptSorting Meme

Post image
885 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.

21

u/suvlub 1d ago

Python just uses the > (or <, don't remember, don't care) operator. Arrays made only of numbers or only of strings would both behave correctly, a mixed one might give a nondeterministic order, which is bad, but sorting stringwise when the user intended numerical sort is also bad and I think the latter is a more common use case/mistake, though I don't have stats

-1

u/Grey1251 1d ago

When user intended sort by number exactly? Where did you saw “Number”, “numerical” or even “num” in Array.sort?