We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 14c1e03 + 291c8d7 commit 9c3af75Copy full SHA for 9c3af75
basic/findLongestWord.md
@@ -0,0 +1,35 @@
1
+# Find the Longest Word in a String
2
+
3
+Return the length of the longest word in the provided sentence.
4
5
+Your response should be a number.
6
7
+### 1. Answers
8
9
+```javascript
10
+function findLongestWord(str) {
11
12
+ var arr = str.split(' ');
13
14
+ var max = 0;
15
16
+ for (var i = 0; i < arr.length; i++) {
17
+ var valStr = arr[i].length;
18
19
+ if (valStr > max) {
20
+ max = valStr;
21
+ }
22
23
+ return max;
24
+}
25
26
+findLongestWord("The quick brown fox jumped over the lazy dog");
27
+```
28
29
+### 2. Explain
30
31
+1. We create a arr with the str
32
+2. Setup a var for tracked the length of the bigger
33
+3. Loop inside the arr
34
+4. Setup a var for shortcut the length
35
+5. If the new one is bigger than the prev one make it the new bigger
0 commit comments