Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, it makes sense to sort strings when you get handed strings, and sort numbers when handed numbers. Period. Default behavior is now exactly as expected by 100% of developers.

Your creativity as a language designer should only come in to play when dealing with sets of mixed type.



So how should [1, "a", 2, 3] be sorted by default?


Both Python and Erlang would return [1,2,3,"a"], Ruby and Clojure won't allow the comparison. Either of these approaches makes more sense than JavaScript's.


Javascript returns [1,2,3,a]. What's the problem.


    > [1,2,"10",3].sort()
    [ 1, '10', 2, 3 ]
That's the problem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: