Travis build: 1415

This commit is contained in:
30secondsofcode
2018-01-25 11:43:21 +00:00
parent bca75007c6
commit 92016c7998
4 changed files with 52 additions and 4 deletions

View File

@ -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}
```