From 80ab4013d0a99342dc70c2f4210866f0cb6e6d3b Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 10 Oct 2018 18:02:26 +0000 Subject: [PATCH] Travis build: 630 --- README.md | 2 +- docs/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b2751beb3..a7ed5b554 100644 --- a/README.md +++ b/README.md @@ -2858,7 +2858,7 @@ Return the last set converted to an array. ```js const unionBy = (a, b, fn) => { - const s = new Set(a.map(v => fn(v))); + const s = new Set(a.map(fn)); return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))])); }; ``` diff --git a/docs/index.html b/docs/index.html index 661a471df..33fa8f86d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -543,7 +543,7 @@ managers; //

union

Returns every element that exists in any of the two arrays once.

Create a Set with all values of a and b and convert to an array.

const union = (a, b) => Array.from(new Set([...a, ...b]));
 
union([1, 2, 3], [4, 3, 2]); // [1,2,3,4]
 

unionBy

Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.

Create a Set by applying all fn to all values of a. Create a Set from a and all elements in b whose value, after applying fn does not match a value in the previously created set. Return the last set converted to an array.

const unionBy = (a, b, fn) => {
-  const s = new Set(a.map(v => fn(v)));
+  const s = new Set(a.map(fn));
   return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))]));
 };
 
unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2]