Update intersectionBy.md
This commit is contained in:
@ -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]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user