Find the Longest Word in a String, freeCodeCamp review Basic Algorithm Scripting, lesson 4

preview_player
Показать описание
freeCodeCamp tutorial, review and help, in this challenge we are faced with the daunting task of finding the longest word in a string. We utilize concepts for past lessons such as .split, for loops, and if statements.
Рекомендации по теме
Комментарии
Автор

Absolutely wonderful video! It is great how you break down the logic and explain everything in basic English. If you would create more tutorials like these, that is something I would pay for...hands down!

falvaart
Автор

I love how you walk through the loops!!! best source I've found for understanding the material :-) THANK YOU!!!

garyhignight
Автор

Hi Jose, thanks for the explanation on this. Struggling to put together a working for loop, I did some reading up and cobbled together the following:

/*
count = function (number) {
return number.length;
};

function findLongestWord(str) {
var wordArray = str.split(" ").map(count); //used the callback of map to call the count function (above) on each element of the array and assign that to wordArray
wordArray.sort(function(a, b){return b - a;}); //sort numbers highest to lowest
return wordArray[0]; //return first element (highest)
}

findLongestWord("The quick brown fox jumped over the lazy dog");
*/

Cheers!

jrlx
Автор

This explained the problem very well. Thank you! I was able to rewrite the code on my own (not just c&p) after watching the explanation.

gcho
Автор

Thank you for your videos, they have been very helpful. I try to figure the problems out on my own, then watch the videos to follow your logic if I get stuck.

boxingexcellence
Автор

I did this:
function findLongestWord(str) {
var array = str.split(' ');
array = array.sort(function(a, b) {
return b.length - a.length; //returns array of strings sorted from largest to shortest
});

return array[0].length;
}

tomuthynguyen
Автор

damnit thank you for actually explaining what's happening

xxleben
Автор

Hello Jose, please explain why we need to enter (" ") on line 3 after the .split?
Many thanks
Deryck

deryckaustin
Автор

Even after copying your codes, i still can't solve it LMAO

fancyAlex
visit shbcf.ru