From 76005943e2077a3df1cb554a391c91fd19e52572 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Tue, 16 Oct 2018 08:30:05 +0000 Subject: [PATCH] Travis build: 644 --- README.md | 2 +- docs/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 10f4d69ca..cfc3c1a51 100644 --- a/README.md +++ b/README.md @@ -1010,7 +1010,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/docs/index.html b/docs/index.html index fb657e887..5c0caad10 100644 --- a/docs/index.html +++ b/docs/index.html @@ -118,7 +118,7 @@

compact

Removes falsey values from an array.

Use Array.prototype.filter() to filter out falsey values (false, null, 0, "", undefined, and NaN).

const compact = arr => arr.filter(Boolean);
 
compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]); // [ 1, 2, 3, 'a', 's', 34 ]
 

countBy

Groups the elements of an array based on the given function and returns the count of elements in each group.

Use Array.prototype.map() to map the values of an array to a function or property name. Use Array.prototype.reduce() to create an object, where the keys are produced from the mapped results.

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