-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongest_word.js
64 lines (42 loc) · 1.32 KB
/
longest_word.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
I need to review strings.. do a for in loop and check and keep longest word in a var?
Ok im here
Split a string into an array of substrings:
var str = "How are you doing today?";
var res = str.split(" "); result of res will be an array with the values:
How,are,you,doing,today?
ok, no problem
*/
// function findLongestWord_v1(str) {
// var i = [];
// var count = 0;
// var high = 0;
// i= str.split("");
// console.log(i)
// for (count in str){
// if (str[count] > str[count+1]){
// high = str[count]
// } else {high = str[count+1];}
// }
// return high;
// }
//hey mine worked
findLongestWord('The quick brown fox jumped over the lazy dog');
//I will do mine here ok?
//Any questions about my code? its good it works fine.... Did you understand my code? it's good to know what are you pasting in freecodecamp
//So another file? For the next challenge. Yes I was using for in loop ..yours is clear using word.length directly..ok next
//Do another file
function findLongestWord(str) {
var words = str.split(" ");
var longest = 0;
for(var i = 0; i < words.length; i++){
var word = words[i];
console.log(word);
if(longest < word.length){
longest = word.length;
str = word;
}
}
return str.length;
}
findLongestWord('The quick brown fox jumped over the lazy dog');