Travis build: 1415
This commit is contained in:
35
README.md
35
README.md
@ -412,6 +412,15 @@ average(1, 2, 3);
|
||||
|
||||
</details>
|
||||
|
||||
### _Uncategorized_
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`reduceWhich`](#reducewhich)
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
## 🔌 Adapter
|
||||
|
||||
@ -7327,6 +7336,32 @@ 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
@ -6,11 +6,15 @@ Use `Array.reduce()` in combination with the `comparator` function to get the ap
|
||||
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);
|
||||
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}
|
||||
reduceWhich(
|
||||
[{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }],
|
||||
(a, b) => a.age - b.age
|
||||
); // {name: "Lucy", age: 9}
|
||||
```
|
||||
|
||||
@ -183,6 +183,7 @@ readFileLines:node,array,string
|
||||
redirect:browser,url
|
||||
reducedFilter:array
|
||||
reduceSuccessive:array,function
|
||||
reduceWhich:uncategorized
|
||||
remove:array
|
||||
reverseString:string,array
|
||||
RGBToHex:utility
|
||||
|
||||
Reference in New Issue
Block a user