Update longestItem.md

This commit is contained in:
Angelos Chalaris
2018-01-08 21:58:35 +02:00
committed by GitHub
parent cc71e26fc0
commit 0e828a0f85

View File

@ -1,8 +1,8 @@
### longestItem
Takes any iterable object or object with a `length` property and returns the longest one.
Takes any number of iterable objects or objects with a `length` property and returns the longest one.
The function sorts all arguments by their `length` and returns the first (longest) one.
Use `Array.sort()` to sort all arguments by `length`, return the first (longest) one.
```js
const longestItem = (...vals) => [...vals].sort((a, b) => b.length - a.length)[0];