Merge pull request #857 from Siarhei-Zharnasek/master

Simplify longestItem
This commit is contained in:
Angelos Chalaris
2018-10-25 13:25:07 +03:00
committed by GitHub

View File

@ -7,8 +7,8 @@ Returns `undefined` if no arguments are provided.
Use `Array.prototype.reduce()`, comparing the `length` of objects to find the longest one.
```js
const longestItem = (val, ...vals) =>
[val, ...vals].reduce((a, x) => (x.length > a.length ? x : a));
const longestItem = (...vals) =>
vals.reduce((a, x) => (x.length > a.length ? x : a));
```
```js