Update intersection.md
This commit is contained in:
@ -10,10 +10,10 @@ Create a `Set` from `b`, then use `Array.prototype.filter()` on `a` to only keep
|
|||||||
```js
|
```js
|
||||||
const intersection = (a, b) => {
|
const intersection = (a, b) => {
|
||||||
const s = new Set(b);
|
const s = new Set(b);
|
||||||
return a.filter(x => s.has(x));
|
return [...new Set(a)].filter(x => s.has(x));
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
intersection([1, 2, 3], [4, 3, 2]); // [2, 3]
|
intersection([1, 2, 3], [4, 3, 2]); // [2, 3]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user