Update intersectionBy.md

This commit is contained in:
Angelos Chalaris
2020-02-18 21:29:21 +02:00
committed by GitHub
parent 95f5aca09b
commit 68fbabc5e4

View File

@ -10,10 +10,10 @@ Create a `Set` by applying `fn` to all elements in `b`, then use `Array.prototyp
```js ```js
const intersectionBy = (a, b, fn) => { const intersectionBy = (a, b, fn) => {
const s = new Set(b.map(fn)); const s = new Set(b.map(fn));
return a.filter(x => s.has(fn(x))); return [...new Set(a)].filter(x => s.has(fn(x)));
}; };
``` ```
```js ```js
intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1] intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1]
``` ```