-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort Method .js
More file actions
32 lines (19 loc) · 900 Bytes
/
sort Method .js
File metadata and controls
32 lines (19 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// sort () = method used to sort elements of an array in place
// Sorts elements as strings in javascript in lexicographic ondragover, not alphabetical
// lexicograpghic = (alphabet + numbers + symbols) as strings
//---------------------------------------------- example-1
// let frts = ["Apple","Orange","Bannnana","Coconut","Pineapple"];
// frts.sort();
// console.log(frts);
// let numbers = [1,2,4,10,9,5,20,3];
// // numbers.sort((a,b) => a-b)
// numbers.sort((a,b) => b-a)
// console.log(numbers);
//---------------------- Example-2
// const people = [{name:"Anil",age:25,gpa:4.0},
// {name:"Sunil",age:15,gpa:1.0},
// {name:"Ankita",age:55,gpa:0.1}]
// // people.sort((a,b)=>a.age - b.age)
// // people.sort((a,b)=>b.age -a.age) //reverse order
// people.sort((a,b) => a.name.localeCompare(b.name))
// console.log(people);