MCPcopy Create free account
hub / github.com/material-shell/material-shell / groupBy

Function groupBy

src/utils/group_by.ts:2–14  ·  view source on GitHub ↗
(items: T[], key: (item: T) => K)

Source from the content-addressed store, hash-verified

1/** Groups the given items into a map by their keys */
2export function groupBy<T, K>(items: T[], key: (item: T) => K): Map<K, T[]> {
3 const map = new Map<K, T[]>();
4 for (const item of items) {
5 const k = key(item);
6 let ls = map.get(k);
7 if (ls === undefined) {
8 ls = [];
9 map.set(k, ls);
10 }
11 ls.push(item);
12 }
13 return map;
14}

Callers 1

Calls 3

getMethod · 0.65
setMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected