Update longestString()

This commit is contained in:
Enzo Volkmann
2018-01-07 23:08:48 +01:00
parent 58d9211d25
commit a44f2b8f57

View File

@ -1,9 +1,10 @@
### longestString
Takes an array of strings and returns the longestString one.
Takes an array of strings and returns the longest one.
Uses the [rest operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)
to handle arrays as well as an indefinite amount of single arguments.
Strings are compared using `Array.reduce()`.
```js
const longestString = (...strings) => [...strings].reduce((a, b) => a.length > b.length ? a : b);