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");
``````

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

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.

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.

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.

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