Update snippet descriptions
This commit is contained in:
@ -5,7 +5,8 @@ tags: array,intermediate
|
||||
|
||||
Returns the elements that exist in both arrays, after applying the provided function to each array element of both.
|
||||
|
||||
- Create a `Set` by applying `fn` to all elements in `b`, then use `Array.prototype.filter()` on `a` to only keep elements, which produce values contained in `b` when `fn` is applied to them.
|
||||
- Create a `Set` by applying `fn` to all elements in `b`.
|
||||
- Use `Array.prototype.filter()` on `a` to only keep elements, which produce values contained in `b` when `fn` is applied to them.
|
||||
|
||||
```js
|
||||
const intersectionBy = (a, b, fn) => {
|
||||
@ -16,5 +17,9 @@ const intersectionBy = (a, b, fn) => {
|
||||
|
||||
```js
|
||||
intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1]
|
||||
intersectionBy([{ title: 'Apple' }, { title: 'Orange' }], [{ title: 'Orange' }, { title: 'Melon' }], x => x.title) // [{ title: 'Orange' }]
|
||||
intersectionBy(
|
||||
[{ title: 'Apple' }, { title: 'Orange' }],
|
||||
[{ title: 'Orange' }, { title: 'Melon' }],
|
||||
x => x.title
|
||||
); // [{ title: 'Orange' }]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user