vom laptop

This commit is contained in:
2022-12-05 19:04:39 +01:00
parent f3e85c3145
commit dfaa6f6c4c
22 changed files with 24354 additions and 21372 deletions

21
src/global/tools.ts Normal file
View File

@ -0,0 +1,21 @@
export const groupBy = <T, K extends keyof any>(arr: T[], key: (i: T) => K) =>
arr.reduce((groups, item) =>
{
(groups[key(item)] ||= []).push(item);
return groups;
}, {} as Record<K, T[]>);
export function groupByMap<K, V>(list: Array<V>, keyGetter: (input: V) => K): Map<K, Array<V>>
{
const map = new Map<K, Array<V>>();
list.forEach((item) => {
const key = keyGetter(item);
const collection = map.get(key);
if (!collection) {
map.set(key, [item]);
} else {
collection.push(item);
}
});
return map;
}