Files
30-seconds-of-code/test/countBy/countBy.js
2018-01-15 10:58:44 -05:00

5 lines
173 B
JavaScript

module.exports = countBy = (arr, fn) =>
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
acc[val] = (acc[val] || 0) + 1;
return acc;
}, {});