Simplify countBy
This commit is contained in:
@ -7,7 +7,7 @@ Use `Array.prototype.reduce()` to create an object, where the keys are produced
|
||||
|
||||
```js
|
||||
const countBy = (arr, fn) =>
|
||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
|
||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => {
|
||||
acc[val] = (acc[val] || 0) + 1;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
Reference in New Issue
Block a user