Skip to main content
Module

x/rambda/source/countBy.js

Faster and smaller alternative to Ramda
Latest
File
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}