DEV Community 👩‍💻👨‍💻

Naveen Dinushka
Naveen Dinushka

Posted on

Finding the longest word in a sentence/string (freecodecampnotes)

In this exercise we are given the following snippet to find the longest word in the sentence.

findLongestWordLength(str) {

   return maxLen
}

findLongestWordLength("The quick brown fox jumped over the lazy dog");
Enter fullscreen mode Exit fullscreen mode

Below are our attempts

What is the correct answer? Attempt 2 as always, the reason being..

The split function

Image description

Top comments (0)

Classic DEV post:

CLI tools you won't be able to live without 🔧

CLI tools