-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsort.js
36 lines (31 loc) · 1015 Bytes
/
sort.js
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
33
34
35
36
/*
Example of sort() API
---------------------
You can pass the 'order' parameter to define the ordering.
If you skip the 'order' property the data will be by default
ordered as **ascending**. You need to pass **'desc'** as the
'order' parameter to sort the data in **descending** order.
Also, you can pass a compare function in 'order' parameter
to define your own logic to order the data.
*/
const jsonQ = require('../index.js');
let Q = new jsonQ(__dirname + '/data.json');
const ascSorted = Q.from('arr')
.sort()
.fetch();
console.log('-------- Printing Ascending ordered data ---------');
console.log(ascSorted);
Q = Q.reset();
const descSorted = Q.from('arr')
.sort('desc')
.fetch();
console.log('-------- Printing Descending ordered data ---------');
console.log(descSorted);
Q = Q.reset();
const customSorted = Q.from('arr')
.sort(function(a, b) {
return a - b;
})
.fetch();
console.log('-------- Printing Custom ordered data ---------');
console.log(customSorted);