UNPKG

rambdax

Version:

Extended version of Rambda - a lightweight, faster alternative to Ramda

18 lines (15 loc) 314 B
export function countBy(fn, list){ if (arguments.length === 1){ return _list => countBy(fn, _list) } const willReturn = {} list.forEach(item => { const key = fn(item) if (!willReturn[ key ]){ willReturn[ key ] = 1 } else { willReturn[ key ]++ } }) return willReturn }