-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSortBy.js
More file actions
39 lines (29 loc) · 887 Bytes
/
SortBy.js
File metadata and controls
39 lines (29 loc) · 887 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
33
34
35
36
37
38
39
var sprintf=require("sprintf-js").sprintf;
function typeSort(array_transactions, typeSort) {
if (typeSort == 'n') {
return sortByDescriptionName(array_transactions);
} if (typeSort == 'd') {
return sortByDate(array_transactions);
}
}
function sortByDescriptionName(array_transactions) {
array_transactions.sort(function(a, b) {
var nameA = a.description.toUpperCase();
var nameB = b.description.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
return array_transactions;
}
function sortByDate(array_transactions) {
array_transactions.sort(function(a,b) {
return new Date(a.date).getTime() - new Date(b.date).getTime()
});
return array_transactions;
}
module.exports = typeSort;