I'm not sure it's unexpected.
Javascript has some weird behaviors, but in this case Arrays in Javascript can contain multiple types. How would you sort an array of `['cat', 80.3, '80']`? I think I would expect that to end up as `['80', 80.3, 'cat']`, not `[80.3, '80', 'cat'].
Or to make things more complicated, `['cat', 80.3, { foo: 'bar' }, true]`. Do we want to try and intuit whether that object gets converted to a string or a value? Do we base that intuition on the prototype chain, or what?
I think it makes sense to cast every object/type in the array to a shared format so everything can be compared based on the same criteria.
---
Have simple rules that are universally applied:
- All objects are converted to strings
- Strings are sorted alphabetically
vs something weird like:
- We try to intuit what type you want based on several common type conversions and possibly the prototype
- We have a set of built-in rules about which primitive types (number, boolean, string, Symbol) comes before and after other primitive types.