Travis build: 110

This commit is contained in:
30secondsofcode
2018-07-18 18:03:57 +00:00
parent b129b46c0d
commit 2fc7529f5b
15 changed files with 194 additions and 44 deletions

108
README.md
View File

@ -125,6 +125,7 @@ average(1, 2, 3);
* [`dropWhile`](#dropwhile)
* [`everyNth`](#everynth)
* [`filterNonUnique`](#filternonunique)
* [`filterNonUniqueBy`](#filternonuniqueby)
* [`findLast`](#findlast)
* [`findLastIndex`](#findlastindex)
* [`flatten`](#flatten)
@ -185,6 +186,8 @@ average(1, 2, 3);
* [`unionBy`](#unionby)
* [`unionWith`](#unionwith)
* [`uniqueElements`](#uniqueelements)
* [`uniqueElementsBy`](#uniqueelementsby)
* [`uniqueElementsByRight`](#uniqueelementsbyright)
* [`unzip`](#unzip)
* [`unzipWith`](#unzipwith-)
* [`without`](#without)
@ -1268,6 +1271,39 @@ filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1,3,5]
<br>[⬆ Back to top](#table-of-contents)
### filterNonUniqueBy
Filters out the non-unique values in an array, based on a provided comparator function.
Use `Array.filter()` and `Array.every()` for an array containing only the unique values, based on the comparator function, `fn`.
The comparator function takes four arguments: the values of the two elements being compared and their indexes.
```js
const filterNonUniqueBy = (arr, fn) =>
arr.filter((v, i) => arr.every((x, j) => (i == j) == fn(v, x, i, j)));
```
<details>
<summary>Examples</summary>
```js
filterNonUniqueBy(
[
{ id: 0, value: 'a' },
{ id: 1, value: 'b' },
{ id: 2, value: 'c' },
{ id: 1, value: 'd' },
{ id: 0, value: 'e' }
],
(a, b) => a.id == b.id
); // [ { id: 2, value: 'c' } ]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### findLast
Returns the last element for which the provided function returns a truthy value.
@ -2900,6 +2936,78 @@ uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
<br>[⬆ Back to top](#table-of-contents)
### uniqueElementsBy
Returns all unique values of an array, based on a provided comparator function.
Use `Array.reduce()` and `Array.some()` for an array containing only the first unique occurence of each value, based on the comparator function, `fn`.
The comparator function takes two arguments: the values of the two elements being compared.
```js
const uniqueElementsBy = (arr, fn) =>
arr.reduce((acc, v) => {
if (!acc.some(x => fn(v, x))) acc.push(v);
return acc;
}, []);
```
<details>
<summary>Examples</summary>
```js
uniqueElementsBy(
[
{ id: 0, value: 'a' },
{ id: 1, value: 'b' },
{ id: 2, value: 'c' },
{ id: 1, value: 'd' },
{ id: 0, value: 'e' }
],
(a, b) => a.id == b.id
); // [ { id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' } ]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### uniqueElementsByRight
Returns all unique values of an array, based on a provided comparator function.
Use `Array.reduce()` and `Array.some()` for an array containing only the last unique occurence of each value, based on the comparator function, `fn`.
The comparator function takes two arguments: the values of the two elements being compared.
```js
const uniqueElementsByRight = (arr, fn) =>
arr.reduceRight((acc, v) => {
if (!acc.some(x => fn(v, x))) acc.push(v);
return acc;
}, []);
```
<details>
<summary>Examples</summary>
```js
uniqueElementsByRight(
[
{ id: 0, value: 'a' },
{ id: 1, value: 'b' },
{ id: 2, value: 'c' },
{ id: 1, value: 'd' },
{ id: 0, value: 'e' }
],
(a, b) => a.id == b.id
); // [ { id: 0, value: 'e' }, { id: 1, value: 'd' }, { id: 2, value: 'c' } ]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### unzip
Creates an array of arrays, ungrouping the elements in an array produced by [zip](#zip).