256
kiki
6y

:D sorry, I don’t know who’s author

Comments
  • 18
    That happens when the values are string, not number.
  • 4
    @fireflies unfortunatly numbers too
  • 17
    @norman70688 yes, it truly is a demonstration of stupid default behavior
  • 12
    Well it clearly says it sorts based on unicode...

    Sort should be given a function...

    But yeah. Remember boys and girls, always use documentation and never guess functionality.
  • 2
    why does this seem so confusing to peeps?
  • 1
    @sonofwind Only through implicit conversion would this happen with numbers.
  • 8
    @arjaycodes the sort function should never be called like this. it needs a param function to define the type and the direction of the sort.

    > [0, 1, 10, 2, 3, 8, 9].sort(function(a,b) { return a > b; });

    [0, 1, 2, 3, 8, 9, 10]
  • 3
    @sonofwind That’s pretty much what I was saying
  • 4
    Wtf guys are you serious

    That was just a tiny joke, calm the fuck down
  • 5
  • 2
  • 2
    Shitty Language. Over and out.
  • 0
    Bad "teacher". Sort should be given a lambda expression.
  • 5
    @norman70688 ya. Every time I see something like this, it's just someone not understanding how JavaScript works and after someone like you comments about it, they try to defend them self by blaming someone else.
  • 1
    Whaat.... My whole life about .sort() was a lie....
  • 0
    @curlyDev unless you're writing Python code 😉
  • 2
    Don't trust him, that cat be lion.😬
  • 0
    That was my exact expression when I first came across this in production code
Add Comment