Merge pull request #841 from Siarhei-Zharnasek/master

Simplify countBy
This commit is contained in:
Angelos Chalaris
2018-10-16 11:28:26 +03:00
committed by GitHub
2 changed files with 2 additions and 2 deletions

View File

@ -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;
}, {});

View File

@ -1,5 +1,5 @@
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;
}, {});