sort() in JavaScript converts the sorting items to strings during compare.
That’s why [9, 10].sort() returns [10, 9].
If you need to sort value, you have to extend it with compare lambda:
That’s why [9, 10].sort() returns [10, 9].
If you need to sort value, you have to extend it with compare lambda:
[10, 0].sort(function(a, b) { return a - b; });
Комментариев нет:
Отправить комментарий