1const books = [
2 {id: 1, name: 'The Lord of the Rings'},
3 {id: 2, name: 'A Tale of Two Cities'},
4 {id: 3, name: 'Don Quixote'},
5 {id: 4, name: 'The Hobbit'}
6]
7
8books.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0));
1var array = [
2 {name: "John", age: 34},
3 {name: "Peter", age: 54},
4 {name: "Jake", age: 25}
5];
6
7array.sort(function(a, b) {
8 return a.age - b.age;
9}); // Sort youngest first
1function createDropDowns() {
2 for (const [key, val] of Object.entries($pgns["nmea2000"])) {
3 pgnList = [...pgnList, val];
4 fieldsList[val.title] = val.fields;
5 fieldsListOut[val.title] = val.fields;
6 }
7 pgnList.sort((a, b) =>
8 a.title > b.title ? 1 : b.title > a.title ? -1 : 0
9 );
10}
11
12pgnList = [
13 {pgn: '065280', manufacturer: '161', title: 'Proprietary - Set Serial Number', fields: Array(6), route: '/nmea2000/data/{busNumber}/by_instance/{instance}/065280/{field}'}
14 {pgn: '065280', manufacturer: '257', title: 'Engine Status Parameters, Dynamic', fields: Array(10), route: '/nmea2000/data/{busNumber}/by_instance/{instance}/065280/{field}'}
15 {pgn: '065284', manufacturer: '257', title: 'Display Communication Status', fields: Array(12), route: '/nmea2000/data/{busNumber}/by_instance/{instance}/065284/{field}'}
16 {pgn: '065289', manufacturer: '161', function: '1', title: 'Proprietary - Set Volume and Capacity', fields: Array(8), …}
17 {pgn: '065289', manufacturer: '161', function: '2', title: 'Proprietary' }
18]
1const drinks1 = [
2 {name: 'lemonade', price: 90},
3 {name: 'lime', price: 432},
4 {name: 'peach', price: 23}
5];
6
7function sortDrinkByPrice(drinks) {
8 return drinks.sort((a, b) => a.price - b.price);
9}
1let orders = [
2 {
3 order: 'order 1', date: '2020/04/01_11:09:05'
4 },
5 {
6 order: 'order 2', date: '2020/04/01_10:29:35'
7 },
8 {
9 order: 'order 3', date: '2020/04/01_10:28:44'
10 }
11];
12
13
14console.log(orders);
15
16orders.sort(function(a, b){
17 let dateA = a.date.toLowerCase();
18 let dateB = b.date.toLowerCase();
19 if (dateA < dateB)
20 {
21 return -1;
22 }
23 else if (dateA > dateB)
24 {
25 return 1;
26 }
27 return 0;
28});
29
30console.log(orders);