This was the bug in my code once.
i’m guessing if you put 09 it would do it fine, but it’s sorting first digit by first digit? Windows file systems do that in names of files when sorting alphabetically but i would have thought an actual programming language would do better…
Not quite, but it does do number string type coercions in unexpected places. I honestly have no idea why it makes sense that .sort() has this behavior off the top of my head. The correct solution is to use the underscore.js sorting functionality and not even think about what the built in methods do.
I honestly have no idea why it makes sense that .sort() has this behavior
Purely guessing here, sort() probably works on arrays that have strings. If it does work on arrays of strings, it might automatically coerce everything into a string instead of first checking whether that’s appropriate.