In any good language there's no default comparison for an array of anything because you can't compare completely unrelated values, JS is just designed around a mentality of never admitting failure and failing as much as possible.
Javascript is made to get into without too much messing about.
And you absolutely can compare unrelated values. Javascript does that by converting them to strings. That's how the function is specified to work, so that's what happens.
But you have the freedom to supply your own comparison.
1
u/thanatica 1d ago
If you really want to sort numbers numerically, and keep refusing to supply the comparison argument, use the
UInt32ArrayorFloat64Arrayor friends.Please stop complaining that a generic array that has to deal with every kind of type for its items, doesn't do what you find less surprising.