Files
30-seconds-of-code/snippets/longestString.md
2018-01-07 23:05:55 +01:00

491 B

longestString

Takes an array of strings and returns the longestString one.

Uses the rest operator to handle arrays as well as an indefinite amount of single arguments.

const longestString = (...strings) => [...strings].reduce((a, b) => a.length > b.length ? a : b);
longestString('this', 'is', 'a', 'testcase') // 'testcase'
longestString(['a', 'ab', 'abc']) // 'abc'