From 304b867c6fa5c1192e8cdec7fd22affb50e244b3 Mon Sep 17 00:00:00 2001
From: Akash Keshav <112591754+domesticchores@users.noreply.github.com>
Date: Tue, 25 Mar 2025 09:37:49 -0400
Subject: implement sorting algorithms with selection buttons. -ak
---
.../components/need-list/need-list.component.html | 7 ++++
.../components/need-list/need-list.component.ts | 46 ++++++++++++++++++++--
2 files changed, 50 insertions(+), 3 deletions(-)
(limited to 'ufund-ui/src')
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.html b/ufund-ui/src/app/components/need-list/need-list.component.html
index 36c12d0..c5faf74 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.html
+++ b/ufund-ui/src/app/components/need-list/need-list.component.html
@@ -1,4 +1,11 @@
Needs List
+
+
Sort by:
+
+
+
+
+
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 be444fb..06bb17e 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
@@ -16,13 +16,24 @@ const sortByName: sortAlgo = (a: Need, b: Need): number => {
return 1;
}
+const sortByNameReverse: sortAlgo = (a: Need, b: Need): number => {
+ return sortByName(a,b)*-1;
+}
+
const sortByMaxGoal: sortAlgo = (a: Need, b: Need): number => {
- if(a.maxGoal >= b.maxGoal) {
+ if(a.maxGoal == b.maxGoal) {
+ return sortByName(a,b);
+ }
+ else if(a.maxGoal > b.maxGoal) {
return -1;
}
return 1;
}
+const sortByMinGoal: sortAlgo = (a: Need, b: Need): number => {
+ return sortByMaxGoal(a,b)*-1;
+}
+
@Component({
selector: 'app-need-list',
standalone: false,
@@ -37,6 +48,8 @@ export class NeedListComponent {
SortingAlgoArrays: {func:sortAlgo,name:string}[] = [
{func:sortByMaxGoal,name:"sortByMaxGoal"},
{func:sortByName,name:"sortByName"},
+ {func:sortByNameReverse,name:"sortByNameReverse"},
+ {func:sortByMinGoal,name:"sortByMinGoal"},
];
constructor(
--
cgit v1.2.3