diff --git a/GuessNN-webapp/src/Utils.ts b/GuessNN-webapp/src/Utils.ts index 0b6e5bd..776df14 100644 --- a/GuessNN-webapp/src/Utils.ts +++ b/GuessNN-webapp/src/Utils.ts @@ -6,3 +6,14 @@ export function fetchJSON(url: string): Promise { return response.json(); }); } + +export function groupBy(list: Iterable, mapper: (_el: V) => K): Map { + const result = new Map(); + for (const el of list) { + const key = mapper(el); + if (!result.has(key)) + result.set(key, []); + result.get(key).push(el); + } + return result; +}