UNPKG

rambda

Version:

Lightweight and faster alternative to Ramda with included TS definitions

17 lines (14 loc) 273 B
export function countBy(fn) { return list => { const willReturn = {} list.forEach(item => { const key = fn(item) if (!willReturn[key]) { willReturn[key] = 1 } else { willReturn[key]++ } }) return willReturn } }