Basic Algorithm Scripting - Find the Longest Word in a String

Need help understanding where Im wrong. Also, would love to see other solutions.

Show me another way to set this code up! Thank yall

  **Your code so far**
function findLongestWordLength(str) {
const array = str.split('')
const wordLengths = array.map((word) => {
  return word.length
})

return Math.max(...wordLengths)

}

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/104.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Find the Longest Word in a String

Link to the challenge:

Can you say something more specific than ‘I’m wrong’? Which test cases are failing?

Is there any space in that split?

2 Likes
function findLongestWordLength(str) {
const array = str.split('')
console.log(array)//LOOK at output
const wordLengths = array.map((word) => {
  return word.length
})

return Math.max(...wordLengths)

}



console.log(findLongestWordLength("The quick brown fox jumped over the lazy dog"));


/*
Output:

[
  'T', 'h', 'e', ' ', 'q', 'u', 'i',
  'c', 'k', ' ', 'b', 'r', 'o', 'w',
  'n', ' ', 'f', 'o', 'x', ' ', 'j',
  'u', 'm', 'p', 'e', 'd', ' ', 'o',
  'v', 'e', 'r', ' ', 't', 'h', 'e',
  ' ', 'l', 'a', 'z', 'y', ' ', 'd',
  'o', 'g'
]
1
*/
1 Like

it was the space, thank you kindly!!!

I was failing every line of code!

Thanks for the fresh eyes!!!

1 Like

thank you for this. :laughing: :laughing: :laughing: :laughing:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.