I’m refreshing my Javascript knowledge by going through all the JS curriculum. Currently, I’m in “Find the Longest Word in a String” that’s under “Basic Algorithm Scripting” section. I know that I can easily solve this with .split() method. However, I haven’t came across this .split() method yet before encountering this “Find the longest word” problem. Since I was acting like I’m a new programmer, I managed to write this solution with what I’ve learned so far.
function findLongestWordLength(str) {
let count = 0;
let arr = [];
let wordCount = "";
for (let i = 0; i < str.length; i++) {
if(str[i] !== " ") {
wordCount += str[i];
} else {
if(wordCount.length >= count) {
count = wordCount.length;
}
wordCount = "";
}
}
if(wordCount !== "") {
if(wordCount.length >= count) {
count = wordCount.length;
}
}
return count;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
Hei that’s strange. Did the course some time ago and clearly remembered that they talked about the .split() method.
Don’t know if Functional Programming was moved around but now it’s clearly here. So you’d had to also do OOP before reaching it. Might really be confusing for some
Exactly, it looks like “Functional Programming” section was placed after “Basic Algorithm Scripting”. Normally, people will move down from top while learning Javascript. Therefore, if they came across this problem without doing “Functional Programming”, they would be confused.
There are a variety of solutions in the guide. Some of the guide solutions use more advanced techniques that have not yet been covered at that point in the curriculum, but every challenge can be solved with the material covered in the course so far.
Right. However, for new programmers who’s struggling to understand this problem and then went to this Guide to look at solutions would see the split().method that hasn’t been covered yet. They would be confused at this point realizing that they haven’t came across that yet.
I’m just pointing this problem out from the view of new programmers.
I don’t really see this as a problem. The suggested solutions in the guide are just there to provide alternatives after the user has solved the problem.