Skip to content

Commit d6aeb1b

Browse files
luismunoz83luismunoz83
authored andcommitted
Second commit, iteraccion 2
1 parent d013ab6 commit d6aeb1b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/functions-and-arrays.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ console.log(maxOfTwoNumbers(7,8))
1111
// Iteration #2: Find longest word
1212
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
1313

14-
function findLongestWord() {}
14+
function findLongestWord(words) {
15+
16+
let wordTop = words[0];
17+
18+
for (let i = 0; i < words.length; i++) {
19+
if (words[i].length > wordTop.length) {
20+
wordTop = words[i]
21+
}
22+
}
23+
24+
return wordTop;
25+
26+
}
27+
28+
console.log(findLongestWord(words))
29+
1530

1631

1732

0 commit comments

Comments
 (0)