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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import {Need} from '../../models/Need';
interface sortAlgo {
(a: Need, b: Need): number;
}
// sort functions
const sortByName: sortAlgo = (a: Need, b: Need): number => {
if(a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
return -1;
}
return 1;
}
const sortByGoal: sortAlgo = (a: Need, b: Need): number => {
if(a.maxGoal == b.maxGoal) {
return sortByName(a,b);
}
else if(a.maxGoal > b.maxGoal) {
return -1;
}
return 1;
}
const sortByCompletion: sortAlgo = (a: Need, b: Need): number => {
if(a.current == b.current) {
return sortByGoal(a,b);
}
else if(a.current > b.current) {
return -1;
}
return 1;
}
const sortByPriority: sortAlgo = (a: Need, b: Need): number => {
if(a.urgent == b.urgent) {
return sortByGoal(a,b);
}
else if(a.urgent && !b.urgent) {
return -1;
}
return 1;
}
const sortByLocation: sortAlgo = (a: Need, b: Need): number => {
if(a.location.toLocaleLowerCase() < b.location.toLocaleLowerCase()) {
return -1;
}
return 1;
}
const sortByType: sortAlgo = (a:Need, b:Need): number => {
if(a.type == b.type) {
return sortByName(a,b);
}
else if(a.type > b.type) {
return -1;
}
return 1;
}
export const SortingAlgoArrays: {[key: string]: { func: sortAlgo, display: [string, string]}} = {
sortByPriority: { func: sortByPriority, display: ["Highest Priority", "Lowest Priority" ] },
sortByName: { func: sortByName, display: ["Name (A to Z)", "Name (Z to A)" ] },
sortByLocation: { func: sortByLocation, display: ["Location (A to Z)", "Location (Z to A)" ] },
sortByCompletion: { func: sortByCompletion, display: ["Most Completed", "Least Completed" ] },
sortByGoal: { func: sortByGoal, display: ["Largest Maximum Goal", "Smallest Maximum Goal" ] },
sortByType: { func: sortByType, display: ["Type (Physical first)", "Type (Monetary first)" ] },
};
|