File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ All of these examples are from FreeCodeCamp's [course](https://www.freecodecamp.
1414 - [ 1. Convert Celsius to Fahrenheit] ( #1-convert-celsius-to-fahrenheit )
1515 - [ 2. Reverse a String] ( #2-reverse-a-string )
1616 - [ 3. Factorialize a Number] ( #3-factorialize-a-number )
17+ - [ 4. Find the Longest Word in a String] ( #4-find-the-longest-word-in-a-string )
1718
1819## Basic Algorithm Scripting
1920
@@ -118,4 +119,33 @@ function factorialize(num) {
118119factorialize(5);
119120
120121
122+ ```
123+
124+ ### 4. Find the Longest Word in a String
125+
126+ ### Difficulty: Beginner
127+
128+ Return the length of the longest word in the provided sentence.
129+
130+ Your response should be a number.
131+
132+ ---
133+
134+ ### Solution 1
135+
136+ ```
137+ function findLongestWordLength(str) {
138+ let splitWords = str.split(" ");
139+ let longestWordLength = 0;
140+
141+ for (let i = 0; i < splitWords.length; i++) {
142+ if (splitWords[i].length > longestWordLength) {
143+ longestWordLength = splitWords[i].length;
144+ }
145+ }
146+ return longestWordLength;
147+ }
148+
149+ findLongestWordLength("The quick brown fox jumped over the lazy dog");
150+
121151```
You can’t perform that action at this time.
0 commit comments