1
Fork 0
mirror of https://github.com/Steffo99/todocolors.git synced 2024-11-26 02:04:17 +00:00

Create groupAndSortTasks function

This commit is contained in:
Steffo 2023-08-02 13:23:44 +02:00
parent 3c6b9ba36e
commit 7549d4e1e3
Signed by: steffo
GPG key ID: 2A24051445686895

View file

@ -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;
}