So I’m currently going through the algorithm section and encountering a lot of trouble.
I’m sure some of it is because I haven’t been writing in JavaScript for very long but I wanted to get some feedback from you guys and see if I am on the right road.
The code isn’t finished but I’m honestly scratching my head wondering what I have to do to make it to the solution.
Thoughts?
function findLongestWord(str) {
// This will keep track of the longest word globally
var count = 0;
// This code splits up the code into an array
var stringArray = str.split(' ');
// This code checks the length of each item in the array
for (var i = 0; i < stringArray.length; i++) {
if(stringArray[i].length > count) {
stringArray[i].length = count;
}
}
stringArray.forEach(function() {
})
return longestWord;
}