File tree 1 file changed +30
-0
lines changed
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.
14
14
- [ 1. Convert Celsius to Fahrenheit] ( #1-convert-celsius-to-fahrenheit )
15
15
- [ 2. Reverse a String] ( #2-reverse-a-string )
16
16
- [ 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 )
17
18
18
19
## Basic Algorithm Scripting
19
20
@@ -118,4 +119,33 @@ function factorialize(num) {
118
119
factorialize(5);
119
120
120
121
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
+
121
151
```
You can’t perform that action at this time.
0 commit comments