diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-04-02 23:27:27 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-04-02 23:27:27 -0400 |
commit | 3e5422b90a09d1ed2cfffae56abf8dbe361f6c27 (patch) | |
tree | 3b3fdbd99a4b2a4f990b2f8d8543a80614492142 /ufund-ui/src/app/components/cupboard/sorting.ts | |
parent | 6b7c830eeefb6a6a28136a3faacf7713953a6138 (diff) | |
download | JellySolutions-3e5422b90a09d1ed2cfffae56abf8dbe361f6c27.tar.gz JellySolutions-3e5422b90a09d1ed2cfffae56abf8dbe361f6c27.tar.bz2 JellySolutions-3e5422b90a09d1ed2cfffae56abf8dbe361f6c27.zip |
[incomplete] rearrange code to begin need-list abstraction
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/sorting.ts')
-rw-r--r-- | ufund-ui/src/app/components/cupboard/sorting.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/ufund-ui/src/app/components/cupboard/sorting.ts b/ufund-ui/src/app/components/cupboard/sorting.ts new file mode 100644 index 0000000..a512f22 --- /dev/null +++ b/ufund-ui/src/app/components/cupboard/sorting.ts @@ -0,0 +1,58 @@ +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; +} + +export const SortingAlgoArrays = { + 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" ] }, +}; |