diff --git a/snippets/countBy.md b/snippets/countBy.md index 16aacca5e..f3b7acfb4 100644 --- a/snippets/countBy.md +++ b/snippets/countBy.md @@ -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; }, {}); diff --git a/test/countBy/countBy.js b/test/countBy/countBy.js index e6b0cadf6..83f16c1b7 100644 --- a/test/countBy/countBy.js +++ b/test/countBy/countBy.js @@ -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; }, {});