Simplify intersectionBy
This commit is contained in:
@ -6,7 +6,7 @@ Create a `Set` by applying `fn` to all elements in `b`, then use `Array.filter()
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const intersectionBy = (a, b, fn) => {
|
const intersectionBy = (a, b, fn) => {
|
||||||
const s = new Set(b.map(x => fn(x)));
|
const s = new Set(b.map(fn));
|
||||||
return a.filter(x => s.has(fn(x)));
|
return a.filter(x => s.has(fn(x)));
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const intersectionBy = (a, b, fn) => {
|
const intersectionBy = (a, b, fn) => {
|
||||||
const s = new Set(b.map(x => fn(x)));
|
const s = new Set(b.map(fn));
|
||||||
return a.filter(x => s.has(fn(x)));
|
return a.filter(x => s.has(fn(x)));
|
||||||
};
|
};
|
||||||
module.exports = intersectionBy;
|
module.exports = intersectionBy;
|
||||||
|
|||||||
Reference in New Issue
Block a user