Блог пользователя zhanglinjie_

Автор zhanglinjie_, история, 5 лет назад, По-английски
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
  • Проголосовать: нравится
  • -22
  • Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

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.