Travis build: 1417

This commit is contained in:
30secondsofcode
2018-01-25 11:46:26 +00:00
parent dc7f52bfaf
commit 3a1ffcf693
2 changed files with 40 additions and 45 deletions

View File

@ -135,6 +135,7 @@ average(1, 2, 3);
* [`pullAtValue`](#pullatvalue)
* [`reducedFilter`](#reducedfilter)
* [`reduceSuccessive`](#reducesuccessive)
* [`reduceWhich`](#reducewhich)
* [`remove`](#remove)
* [`sample`](#sample)
* [`sampleSize`](#samplesize)
@ -412,15 +413,6 @@ average(1, 2, 3);
</details>
### _Uncategorized_
<details>
<summary>View contents</summary>
* [`reduceWhich`](#reducewhich)
</details>
---
## 🔌 Adapter
@ -1726,6 +1718,35 @@ reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0); // [0, 1, 3, 6
<br>[⬆ Back to top](#table-of-contents)
### reduceWhich
Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule.
Use `Array.reduce()` in combination with the `comparator` function to get the appropriate element in the array.
You can omit the second parameter, `comparator`, to use the default one that returns the minimum element in the array.
```js
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a));
```
<details>
<summary>Examples</summary>
```js
reduceWhich([1, 3, 2]); // 1
reduceWhich([1, 3, 2], (a, b) => b - a); // 3
reduceWhich(
[{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }],
(a, b) => a.age - b.age
); // {name: "Lucy", age: 9}
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### remove
Removes elements from an array for which the given function returns `false`.
@ -7336,32 +7357,6 @@ yesNo('Foo', true); // true
<br>[⬆ Back to top](#table-of-contents)
---
## _Uncategorized_
### reduceWhich
Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule.
Use `Array.reduce()` in combination with the `comparator` function to get the appropriate element in the array.
You can omit the second parameter, `comparator`, to use the default one that returns the minimum element in the array.
```js
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a));
```
```js
reduceWhich([1, 3, 2]); // 1
reduceWhich([1, 3, 2], (a, b) => b - a); // 3
reduceWhich(
[{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }],
(a, b) => a.age - b.age
); // {name: "Lucy", age: 9}
```
<br>[⬆ back to top](#table-of-contents)
## Collaborators

File diff suppressed because one or more lines are too long