Skip to content

Commit 325dc4a

Browse files
committed
iteration ironhack-labs#2
1 parent c51d213 commit 325dc4a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/functions-and-arrays.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ function maxOfTwoNumbers(a, b) {
99
}
1010
}
1111

12-
13-
1412
// Iteration #2: Find longest word
1513
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
1614

17-
function findLongestWord() {}
18-
19-
15+
function findLongestWord(arr) {
16+
let longestWord = ""
17+
if (arr.length === 0) {
18+
return null
19+
}
20+
for (let i = 0; i < arr.length; i++) {
21+
if (arr[i].length > longestWord.length) {
22+
longestWord = arr[i]
23+
}
24+
}
25+
return longestWord
26+
}
2027

2128
// Iteration #3: Calculate the sum
2229
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

0 commit comments

Comments
 (0)