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

Function keyBy

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

Source from the content-addressed store, hash-verified

12};
13
14export const keyBy = <T, K>(array: T[], keyOf: (item: T) => K): Map<K, T> => {
15 return array.reduce((map, item) => {
16 const key = keyOf(item);
17 map.set(key, item);
18 return map;
19 }, new Map<K, T>());
20};
21
22export const upsertArray = <T>(array: T[], item: T) => {
23 const index = array.indexOf(item);

Callers 2

isEqualIndexesMethod · 0.90

Calls 2

keyOfFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected