Tell us what’s happening:
Right now I need to figure out how to separate each of the strings from the whole of the sentence. Right now using the .length function on the string, it counts all the letters of all the words. I figure that identifying the spaces might be useful potentially using the regular expressions or .match functions. Looking for some advice if you have some!
Your code so far
function findLongestWordLength(str) {
let x = [str];
console.log(str.length);
return str.length;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
Creating an array of words from a given string can be accomplished using String.prototype.split(' ').
If you wanted to convert a string containing a few sentences worth of text into an array of characters rather than the above code for an array of words, you would simply use String.prototype.split('').