Jla
September 4, 2020, 12:16pm
1
Tell us what’s happening:
Your code so far
function findLongestWordLength(str) {
str = str.split(" ");
if (str.length == 1) {
return str[0].length;
}
}
if (str[0].length >= str[1].length) {
str.splice(1, 1);
return findLongestWordLength(str.join(" "));
}
if (str[0].length <= str[1].length) {
return findLongestWordLength(str.slice(1, str.length).join(" "));
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
.
Challenge: Find the Longest Word in a String
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
miles
September 4, 2020, 2:04pm
2
So your function should be returning the length of the longest word.
You might try using a for loop.
Let me know if that helps
lasjorg
September 4, 2020, 2:20pm
3
You closed the function after the first if statement. Move the closing }
to the bottom.
The ultimate goal here is to return the largest string in a sentence. You’re going into the right direction when you think of str.split, but think to yourself: “is that really a string?” Hint: this is where typescript comes in handy. Then you want to find a way to find each length of the number, and find the max.
Another Hint: Math.max() could help you.
lasjorg
September 4, 2020, 2:40pm
5
The code works just fine, it’s just a malformed function. All they need to do is closed the function correctly.