Skip to content

Commit b1ba65d

Browse files
ITERATION ironhack-labs#2 COMPLETED
1 parent bc3a7b8 commit b1ba65d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
// Iteration #1: Find the maximum
2-
2+
function maxOfTwoNumbers(num1, num2) {
3+
if (num1 > num2) {
4+
return num1;
5+
}
6+
else {
7+
return num2;
8+
}
9+
}
310
// Iteration #2: Find longest word
411
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
12+
function findLongestWord(anArray) {
13+
if (anArray.length === 0) {
14+
return null;
15+
}
16+
let longestWord = anArray[0];
17+
anArray.forEach((aSingleWord) => {
18+
if (aSingleWord.length > longestWord.length) {
19+
longestWord = aSingleWord;
20+
}
21+
})
22+
return longestWord;
23+
}
524

625
// Iteration #3: Calculate the sum
726

0 commit comments

Comments
 (0)