javascript Сортировка массива чисел, пример кода
Primary tabs
По возрастанию:
let arr = [1, 5, 4, 10, 3];
arr.sort(function(a, b) {
return a - b;
});
console.log(arr);
По убыванию:
let arr = [1, 5, 4, 10, 3];
arr.sort(function(a, b) {
return b - a;
});
console.log(arr);
- Log in to post comments
- 1925 reads