Skip to content

Commit debf160

Browse files
committed
Iteration ironhack-labs#2
1 parent 0f94b74 commit debf160

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/functions-and-arrays.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
// Iteration #1: Find the maximum
2-
2+
function maxOfTwoNumbers(num1, num2){
3+
if (num1 > num2){
4+
return num1
5+
}else{
6+
return num2
7+
}
8+
}
39
// Iteration #2: Find longest word
410
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
511

6-
// Iteration #3: Calculate the sum
12+
function findLongestWord(list1){
13+
let lenList = list1.length
14+
let longestWord = "";
15+
for(let i=0;i<lenList;i++){
16+
if(list1[i].length >longestWord.length){
17+
longestWord = list1[i]
18+
}
719

20+
}
21+
if(longestWord === ""){
22+
return null
23+
}else{
24+
return longestWord}
25+
}
26+
// Iteration #3: Calculate the sum
827
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
928

29+
30+
function sumNumbers(array1){
31+
let totalSum = 0;
32+
let listSize = array1.length;
33+
34+
for(let i=0;i <listSize; i++){
35+
totalSum =totalSum + array1[0];
36+
}
37+
return totalSum
38+
39+
}
1040
// Iteration #4: Calculate the average
1141
// Level 1: Array of numbers
1242
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

0 commit comments

Comments
 (0)