Skip to content

Commit 218e947

Browse files
committed
Add Iteration ironhack-labs#2
1 parent 6ed355f commit 218e947

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/functions-and-arrays.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,29 @@ function maxOfTwoNumbers(num1, num2) {
88
return num1;
99
}
1010
}
11-
console.log(maxOfTwoNumbers(11,10));
11+
console.log(maxOfTwoNumbers(11,10));
12+
13+
// Iteration #2: Find longest word
14+
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
15+
16+
let findLongestWord = (arr) => {
17+
let result;
18+
if (arr.length > 0){
19+
let largest = "";
20+
words.forEach((el) => {
21+
if(largest.length < el.length){
22+
largest = el;
23+
}
24+
});
25+
return largest;
26+
} else if (arr.length = 1){
27+
28+
return arr[0];
29+
30+
} else if (arr.length === 0){
31+
result = null;
32+
}
33+
return result;
34+
}
35+
36+
console.log(findLongestWord(words));

0 commit comments

Comments
 (0)