UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

11 lines (9 loc) 259 B
function countBy(set, mapper) { const result = new Map(); for (const value of set) { const mappedKey = mapper(value, value, set); result.set(mappedKey, (result.get(mappedKey) ?? 0) + 1); } return result; } export { countBy };