Travis build: 1368

This commit is contained in:
30secondsofcode
2018-01-24 10:21:11 +00:00
parent 8c3cd669eb
commit 56d84c429e
3 changed files with 62 additions and 4 deletions

View File

@ -142,6 +142,8 @@ average(1, 2, 3);
* [`take`](#take) * [`take`](#take)
* [`takeRight`](#takeright) * [`takeRight`](#takeright)
* [`union`](#union) * [`union`](#union)
* [`unionBy`](#unionby)
* [`unionWith`](#unionwith)
* [`uniqueElements`](#uniqueelements) * [`uniqueElements`](#uniqueelements)
* [`without`](#without) * [`without`](#without)
* [`zip`](#zip) * [`zip`](#zip)
@ -1892,6 +1894,56 @@ union([1, 2, 3], [4, 3, 2]); // [1,2,3,4]
<br>[⬆ Back to top](#table-of-contents) <br>[⬆ Back to top](#table-of-contents)
### unionBy
Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.
Create a `Set` by applying all `fn` to all values of `a`.
Create a `Set` from `a` and all elements in `b` whose value, after applying `fn` does not match a value in the previously created set.
Return the last set converted to an array.
```js
const unionBy = (a, b, fn) => {
const s = new Set(a.map(v => fn(v)));
return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))]));
};
```
<details>
<summary>Examples</summary>
```js
unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### unionWith
Returns every element that exists in any of the two arrays once, using a provided comparator function.
Create a `Set` with all values of `a` and values in `b` for which the comparator finds no matches in `a`, using `Array.findIndex()`.
```js
const unionWith = (a, b, comp) =>
Array.from(new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)]));
```
<details>
<summary>Examples</summary>
```js
unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2, 1.5, 3, 0, 3.9]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### uniqueElements ### uniqueElements
Returns all unique values of an array. Returns all unique values of an array.

File diff suppressed because one or more lines are too long

View File

@ -6,9 +6,7 @@ Create a `Set` with all values of `a` and values in `b` for which the comparator
```js ```js
const unionWith = (a, b, comp) => const unionWith = (a, b, comp) =>
Array.from( Array.from(new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)]));
new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)])
);
``` ```
```js ```js