Basic Algorithm Scripting - Find the Longest Word in a String

This challenge seems out of place to me. The solution requires using the split() function which hasnt even been covered up to this point in the curriculum. The split() function is covered in the functional programming section, which is 2 sections after this Basic Algorithm Scipting section.

function findLongestWordLength(str) {
  let words = str.split(" ");
  let maxLength = 0;
  for (let i = 0; i < words.length; i++) {
    if (words[i].length > maxLength) {
      maxLength = words[i].length;
    }
  }
  return maxLength;
}

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; rv:105.0) Gecko/20100101 Firefox/105.0

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

Link to the challenge:

Use of split is not mandatory.

Why do the hints explicitly ask if you remember how to use split()? There are 5 possible solutions and split is required in all solutions except for the last solution listed. What merit determines how the order in which the available solutions are listed?

The solution that doesnt require split() is clearly not best practice, especially if you take the curriculums recommendations regarding verboseness at face value.

Because that’s the easiest way to do this.

They are listed in the order they were added.

Why ‘clearly’? It works. That is the #1 requirement for a solution. It is more verbose, sure, but it meets your requirement that it only use content explicitly covered to this point in the curriculum.

Its clear that solution is not best practice because it is the solution that is listed last. In spite of the 4 solutions that precede it not even having been covered yet.

In addition to that solution being the most verbose. Which the curriculum is teaching should be taken into consideration in real world scenarios when working with other programmers as part of a team.

If a user did not know about the split method, then the 5th solution or another variation of the 5th solution would be as “best practice” as could be written. Ignorance is bliss.

Another important concept taught throughout the curriculum is Read, Search, Ask. The second part (Search) can be used by a user to search for possible ways of handling a challenge. The split method would probably show up quickly in such a search, hence that is why you see it in 4 of the 5 solutions.

Should the split method have been taught before the Basic Algorithm Scripting section? Maybe, but it was decided to keep it in the Functional Programming section as that is a better fit. Plus, as already mentioned, it is absolutely not necessary to use split to solve the challenge.

Order has nothing to do with quality.

Maybe the order has nothing to do with quality, but that doesnt reflect my experience. In my experience, when there is more than one solution available, the solutions tend to be listed in order of cleanliness and recentness.

I dont recall coming across a legacy solution that had been provided a more favorable position over a more recent solution.

I’m literally the person who put the solution there. Order doesn’t correlate to quality.

I now moved that solution to first. That does not mean it is the best solution ever created for this problem in the history of all possible solutions ever created.

I never said it was the best possible solution. The point I was trying to make is that that specific solution was the only valid solution when taking into account what the curriculum had taught up to this point.

The hints are literally asking if you remember lessons that havent even been covered yet. Instead of trying to solve the challenge with skills that have been covered, I was lead down an untreaded path with foreign tools.

Its not a big deal. But in regards to this specific challenge, and all the emphasis placed on the split function, it just seemed like a bit of a curveball is all.

Now that I know about the split function, then I consider the cleanest split solution to be the best possible solution.

That is not true. The hints in the Guide for this challenge are:

Hints

Hint 1

You will need to loop through the words in the string.

Hint 2

You will need to figure out a way to keep track globally of the greatest current length.

Hint 3

Do you remember how to get the length of strings?

What lead you down the path to use split? If you mean the solutions, then those are not hints, those are the solutions. Once you look at a solution, you are no longer solving the challenge. Instead, you are basically copying/pasting parts of a given solution.

No. If a solution passes without hardcoding or other ‘cheats’, then it is valid. All 5 of those solutions are ‘valid’.

Not at all. Split is not mentioned in the hints anywhere. It hasn’t been part of the hints for quite a while.


I specifically added the non-split solution because people incorrectly kept saying that this challenge was impossible with the content strictly included in the curriculum.

You can solve challenges with the content in the curriculum thus far, but external research is encouraged and may result in simpler solutions.