Travis build: 1364

This commit is contained in:
30secondsofcode
2018-01-24 09:50:52 +00:00
parent 541103321a
commit 8944872760
2 changed files with 34 additions and 1 deletions

View File

@ -98,6 +98,7 @@ average(1, 2, 3);
* [`countOccurrences`](#countoccurrences)
* [`deepFlatten`](#deepflatten)
* [`difference`](#difference)
* [`differenceBy`](#differenceby)
* [`differenceWith`](#differencewith)
* [`dropElements`](#dropelements)
* [`dropRight`](#dropright)
@ -726,6 +727,32 @@ difference([1, 2, 3], [1, 2, 4]); // [3]
<br>[⬆ Back to top](#table-of-contents)
### differenceBy
Returns the difference between two arrays, after applying the provided function to each array element of both.
Create a `Set` by applying `fn` to each element in `b`, then use `Array.filter()` in combination with `fn` on `a` to only keep values not contained in the previously created set.
```js
const differenceBy = (a, b, fn) => {
const s = new Set(b.map(v => fn(v)));
return a.filter(x => !s.has(fn(x)));
};
```
<details>
<summary>Examples</summary>
```js
differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2]
differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [ { x: 2 } ]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### differenceWith
Filters out all values from an array for which the comparator function does not return `true`.

File diff suppressed because one or more lines are too long