// Make use of `map` and `reduce`
const longestWordLength = str => str.split(' ')
.map(w => w.replace(/\W/, ''))
.reduce((longest, current) => (current.length > longest.length) ? current : longest)
.length;
// OR
// Make use of `map` and `Math.max`
const longestWordLength = str => Math.max(
...str.split(' ')
.map(w => w.replace(/\W/, ''))
.map(w => w.length)
);
// Either way...
longestWordLength("Mary had a little lamb.");
// => 6
ErikTheDeveloper
- 171
- 4
ErikTheDeveloper
- 171
- 4
Adds much more comprehensive code examples and links to relevant learning resources
ErikTheDeveloper
- 171
- 4