Skip to content

Commit bd0c40a

Browse files
committed
Iteration ironhack-labs#2: Find longest word
1 parent 0366da9 commit bd0c40a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/functions-and-arrays.js

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

14+
15+
function findLongestWord(list1) {
16+
let lenList = list1.length;
17+
let longestWord = "";
18+
for (let i = 0; i < lenList; i++) {
19+
if(list1[i].length > longestWord.length) {
20+
longestWord = list1[i];
21+
}
22+
}
23+
if(longestWord === "") {
24+
return null
25+
} else {
26+
return longestWord
27+
}
28+
}
29+
1430
// Iteration #3: Calculate the sum
1531

1632
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

0 commit comments

Comments
 (0)