diff --git a/todoblue/src/app/board/[board]/groupAndSortTasks.ts b/todoblue/src/app/board/[board]/groupAndSortTasks.ts new file mode 100644 index 0000000..e3d56ef --- /dev/null +++ b/todoblue/src/app/board/[board]/groupAndSortTasks.ts @@ -0,0 +1,20 @@ +import {Task} from "@/app/board/[board]/types" + + +export function groupAndSortTasks(tasks: Task[], grouping: (a: Task) => string, sorting: (a: Task, b: Task) => number) { + const groups: {[group: string]: Task[]} = {} + + for(const task of tasks) { + const group = grouping(task); + if(!groups[group]) { + groups[group] = []; + } + groups[group].push(task); + } + + for(const group of Object.keys(groups)) { + groups[group].sort(sorting); + } + + return groups; +}