Skip to content

Commit d64ae85

Browse files
Iteration ironhack-labs#2 finished
1 parent bc3a7b8 commit d64ae85

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

starter-code/src/functions-and-arrays.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
// Iteration #1: Find the maximum
2+
function maxOfTwoNumbers(num1, num2) {
3+
if (num1 > num2) {
4+
return num1;
5+
} else {
6+
return num2;
7+
}
8+
}
29

310
// Iteration #2: Find longest word
411
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
512

6-
// Iteration #3: Calculate the sum
13+
function findLongestWord(wordsList) {
14+
let longestWord = '';
15+
if (wordsList.length > 0){
16+
wordsList.forEach(e => {
17+
if (e.length > longestWord.length) {
18+
longestWord = e;
19+
}
20+
});
21+
return longestWord;
22+
} else {
23+
return null;
24+
}
25+
}
726

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

1030
// Iteration #4: Calculate the average

0 commit comments

Comments
 (0)