zhanglinjie_'s blog

By zhanglinjie_, history, 5 years ago, In English
const arr = [10, 11, 9]

arr.sort() // it returns [10, 11, 9] because element be covert to string before sorting

arr.sort((a, b) => a - b)) // it returns [9, 10, 11], you MUST SPECIFY THE COMPARE FUNCTION when sorting numbers
  • Vote: I like it
  • -22
  • Vote: I do not like it

»
5 years ago, hide # |
 
Vote: I like it +24 Vote: I do not like it

Sorry if that comes out harsh, but these 'I wasted 1 hour because ...' posts are pretty much useless. You're expected to read the documentation, and if you had a bug because you don't know or forgot to implement a comparator or something then it's your problem.

If you want to write a post about bugs that would be of use to others, then consider writing one post titled 'Common pitfalls in using JavaScript for competitive programming' with a list of bugs with code samples and explanations.

  • »
    »
    5 years ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    idk, I feel like not all blogs have to be that useful. this one made me laugh a little, so I thought it was cool