how the sort function works javascript
var ages = [18, 21, 9, 41, 35, 24]
ages.sort(function(a, b) {
return a - b
})
// => [9, 18, 21, 24, 35, 41]
const unsorted = ['d', 'd', 'h', 'r', 'v', 'z', 'f', 'c', 'g'];
const sorted = unsorted.sort();
console.log(sorted);
//["c", "d", "d", "f", "g", "h", "r", "v", "z"]
const unsortedNums = [45, 56, 3, 3, 4, 6, 7, 45, 1];
const sortedNums = unsortedNums.sort((a, b) => {
return a - b;
});
console.log(sortedNums);
//[1, 3, 3, 4, 6, 7, 45, 45, 56]
Also in JavaScript:
- <FilterProvider> errorr
- lodash remove element from list
- angular material input
- how to make javascript progarm that randomly displayes a word
- js get timezone name
- js day monday tuesday wednesday
- moment js get date 1 month
- javascript default function parameter value
- jsonplaceholder
- react cheat sheets
- player.filter
- js invert color
- is knex built into node js
- count number of checkboxes in html jquery
- react native flexbox 2 columns 1 fixed width
- how to display a calender in react native
- how the sort function works javascript
- clone an object in javascript
- Image react native
- json stringify close circle
- How to make remove buttoon on table using js DOM
- explain js es6
- minus month javascript date
- js navigate to another page