Find the Longest Word in a String - A solution proposal

Hello, I just solved this and looked over the solutions given in the forum. Here’s mine:

function findLongestWordLength(str) {
  let strArr = str.split(" ");
  let charNum = [];

  for (let word in strArr) {
  return Math.max(...charNum);

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

Am I a terrible person for using Math library functions? I saw the solutions and how some people programmed finding the max number of an array into nifty functions… I am just lazy… Sorry…

Nah dude. It’s actually good that you found a solution that’s different and requires less coding!

1 Like

Many thanks @Bl1xvan. I guess I am learning this js stuff :smiley:

Yeah, learning to code isn’t easy partly because there’s so many different ways to solve one problem. I wish you good luck on your journey!