Skip to content

Commit 204ee3b

Browse files
committed
ironhack-labs#2 completed
1 parent eae2e83 commit 204ee3b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/functions-and-arrays.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@ const maxOfTwoNumbers = (num1, num2) => {
2020

2121

2222
// Iteration #2: Find longest word
23-
// const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
24-
25-
// const findLongestWord = (a, b) => {
26-
27-
// }
23+
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
24+
25+
function findLongestWord(words) {
26+
if(words.length === 0) {
27+
return null;
28+
}
29+
30+
let word = '';
31+
for (let i = 0; i < words.length; i++) {
32+
if (word.length < words[i].length) {
33+
word = words[i];
34+
}
35+
}
36+
return word;
37+
}
2838

2939

3040
// Iteration #3: Calculate the sum

0 commit comments

Comments
 (0)