Skip to content

Commit

Permalink
feat: add sorting by shortest term
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Dec 27, 2023
1 parent 4bb4228 commit f967f67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion components/search/filterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ export function filterData(data: CollegeObject[], filterValues: FilterValues) {
? filteredResults.sort((courseA, courseB) => {
return courseA.tuition - courseB.tuition;
})
: filteredResults;
: filterValues.sort == "Shortest Term"
? filteredResults.sort((courseA, courseB) => {
const termLengthA =
((courseA.endMonth - courseA.startMonth + 12) % 12) *
30 +
(courseA.endDay - courseA.startDay);

const termLengthB =
((courseB.endMonth - courseB.startMonth + 12) % 12) *
30 +
(courseB.endDay - courseB.startDay);

return termLengthA - termLengthB;
})
: filteredResults;

return sortedResults;
}
1 change: 1 addition & 0 deletions components/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ const Search = () => {
"Default Sort",
"Alphabetical",
"Tuition",
"Shortest Term",
]}
onChange={setSort}
/>
Expand Down

0 comments on commit f967f67

Please sign in to comment.