Skip to content

Commit ed6c2a2

Browse files
committed
Iteration ironhack-labs#2
1 parent 3ac78a5 commit ed6c2a2

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/functions-and-arrays.js

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

14-
function findLongestWord() {}
15-
14+
function findLongestWord(anArr) {
15+
16+
if (anArr.length == 0) {
17+
return null
18+
}
19+
20+
let longestWord = ''
21+
22+
for (let i=0; i<anArr.length; i++){
23+
let word = anArr[i];
24+
if (word.length > longestWord.length){
25+
longestWord = word;
26+
}
27+
}
28+
return longestWord
29+
}
1630

1731

1832
// Iteration #3: Calculate the sum

0 commit comments

Comments
 (0)