Simplify longestItem

This commit is contained in:
Siarhei
2018-10-19 14:01:48 +04:00
parent 8dba3032f9
commit dc80418ce0

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