1// Sort an array of numbers
2let numbers = [5, 13, 1, 44, 32, 15, 500]
3
4// Lowest to highest
5let lowestToHighest = numbers.sort((a, b) => a - b);
6//Output: [1,5,13,15,32,44,500]
7
8//Highest to lowest
9let highestToLowest = numbers.sort((a, b) => b-a);
10//Output: [500,44,32,15,13,5,1]
11
1numArray.sort((a, b) => a - b); // For ascending sort
2numArray.sort((a, b) => b - a); // For descending sort
3
1var numArray = [140000, 104, 99];
2numArray.sort(function(a, b) {
3 return a - b;
4});
5
6console.log(numArray);
1let numbers = [5, 2, 8, 1, 4, 6, 3, 7]
2numbers.sort() // sorts the numbers ascending: [1, 2, 3, 4, 5, 6, 7, 8]