mirror of
https://github.com/Steffo99/todocolors.git
synced 2024-11-22 08:14:18 +00:00
Create groupAndSortTasks
function
This commit is contained in:
parent
3c6b9ba36e
commit
7549d4e1e3
1 changed files with 20 additions and 0 deletions
20
todoblue/src/app/board/[board]/groupAndSortTasks.ts
Normal file
20
todoblue/src/app/board/[board]/groupAndSortTasks.ts
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue