diff --git a/README.md b/README.md index d17a287f3..6fc5bc707 100644 --- a/README.md +++ b/README.md @@ -1105,7 +1105,7 @@ Create a `Set` by applying `fn` to each element in `b`, then use `Array.prototyp ```js const differenceBy = (a, b, fn) => { - const s = new Set(b.map(v => fn(v))); + const s = new Set(b.map(fn)); return a.filter(x => !s.has(fn(x))); }; ``` diff --git a/docs/index.html b/docs/index.html index 5c0caad10..da74823bb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -134,7 +134,7 @@ };
difference([1, 2, 3], [1, 2, 4]); // [3]
Returns the difference between two arrays, after applying the provided function to each array element of both.
Create a Set by applying fn to each element in b, then use Array.prototype.filter() in combination with fn on a to only keep values not contained in the previously created set.
const differenceBy = (a, b, fn) => { - const s = new Set(b.map(v => fn(v))); + const s = new Set(b.map(fn)); return a.filter(x => !s.has(fn(x))); };
differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2]