MCPcopy Create free account
hub / github.com/bytebase/bytebase / groupBy

Function groupBy

frontend/src/utils/collections.ts:1–12  ·  view source on GitHub ↗
(
  array: T[],
  keyOf: (item: T) => K
)

Source from the content-addressed store, hash-verified

1export const groupBy = <T, K>(
2 array: T[],
3 keyOf: (item: T) => K
4): Map<K, T[]> => {
5 return array.reduce((map, item) => {
6 const key = keyOf(item);
7 const list = map.get(key) ?? map.set(key, []).get(key)!;
8 list.push(item);
9
10 return map;
11 }, new Map<K, T[]>());
12};
13
14export const keyBy = <T, K>(array: T[], keyOf: (item: T) => K): Map<K, T> => {
15 return array.reduce((map, item) => {

Callers 4

buildInstanceNodeListFunction · 0.90
buildSubTreeFunction · 0.90
layoutELKFunction · 0.85

Calls 3

keyOfFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected