Some methods which will be used in this tutorial:
- split() – This method is used to break a string into words. The delimeter here is blank space. After breaking into words, we can collect all of their lengths and use them to compare.
- map() – The map() method is used to create a new array by mapping each element from the calling array and calling it with an internal function. We use this method to map all separated words’ lengths into an array.
- Math.max – The Math.max() function retrieves the largest of any number of numbers given as parameters, or NaN if an input is not numeric and cannot be converted into a number. This function is used to get the longest length in the array returned by map().
- Spread syntax (…) – Spread syntax, also known as the spread operator, allows an iterable object to be expanded.
Find the Longest Words