From f23afc7f3b0b62384b3b54a0864b02abc3b48b01 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sun, 30 Mar 2025 00:50:43 -0400 Subject: sortByCompletion --- .../src/app/components/need-list/need-list.component.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts') diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 4ae8f4a..17bb3e6 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -26,6 +26,16 @@ const sortByGoal: sortAlgo = (a: Need, b: Need): number => { 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); @@ -52,8 +62,9 @@ export class NeedListComponent { sortSelection: string = 'sortByPriority'; SortingAlgoArrays: {func:sortAlgo,name:string, display:string[]}[] = [ - {func:sortByName,name:"sortByName", display:["Name (Alphabetical)", "Name (Reverse)"]}, + {func:sortByName,name:"sortByName", display:["Name (A to Z)", "Name (Z to A)"]}, {func:sortByGoal,name:"sortByGoal", display:["Largest Maximum Goal", "Smallest Maximum Goal"]}, + {func:sortByCompletion,name:"sortByCompletion", display:["Most Completed", "Least Completed"]}, {func:sortByPriority,name:"sortByPriority", display:["Highest Priority", "Lowest Priority"]}, ]; -- cgit v1.2.3