r/programminghorror
•
u/Leonnee
•
Jun 12 '25
•
1
Javascript Javascript is filled with horror
2.4k
Upvotes
View all comments
Show parent comment
1
u/TorbenKoehn Jun 13 '25
The "wildly" is extremely exaggerated by you.
Calling
(a, b) => a - b"custom code" is an extreme stretch. It's as much "custom code" as calling.sort()is. It allows a lot of flexibility (like descending easily through(a, b) => b - a)Any programming language has these things and they all come down to preference and use-cases. Comparisons by custom functions are some of the first things people learn in programming.
People that want to sort strings don't have "unexpected behavior". neither does the function magically change it's sorting behavior depending on the values inserterd, which is exactly not "unexpected behavior", but a strictly defined and fix behavior.
You're hitting this problem really out of proportion.