Skip to content

Instantly share code, notes, and snippets.

@bazuzu931
Last active February 10, 2017 14:28
Show Gist options
  • Save bazuzu931/26f864b596bb157d67ae590720c88f2b to your computer and use it in GitHub Desktop.
Save bazuzu931/26f864b596bb157d67ae590720c88f2b to your computer and use it in GitHub Desktop.
correct_array_sort.js
[1,2,5,10].sort((a, b) => a- b)
@bazuzu931
Copy link
Author

sort() в JavaScript по умолчанию использует буквенно-цифровой порядок сортировки. Так [1,2,5,10].sort() вернет [1, 10, 2, 5] .
[1, 2, 5, 10].sort() // => [1, 10, 2, 5]
Чтобы получить ожидаемый результат при сортировке массива вы можете использовать предоставленную конструкцию.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment