Skip to content

Commit a8eb7e0

Browse files
committed
1, 3, 4 ironhack-labs#1; 4#2 being worked on
1 parent bc3a7b8 commit a8eb7e0

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
11
// Iteration #1: Find the maximum
2+
function maxOfTwoNumbers (num1, num2) {
3+
if (num1 > num2) {
4+
return num1;
5+
}
6+
else {
7+
return num2;
8+
}
9+
}
210

311
// Iteration #2: Find longest word
412
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
513

14+
function findLongestWord (array) {
15+
let max = null;
16+
array.forEach( (aSingleWord) => {
17+
if(aSingleWord.length > max.length) {
18+
max = aSingleWord;
19+
}
20+
else {
21+
continue;
22+
}
23+
});
24+
return max;
25+
}
26+
627
// Iteration #3: Calculate the sum
728

829
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
930

31+
function sumArray (num) {
32+
let sum = 0;
33+
num.forEach( num1 => {
34+
sum += num1;
35+
36+
})
37+
return sum;
38+
}
39+
40+
1041
// Iteration #4: Calculate the average
1142
// Level 1: Array of numbers
1243
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
1344

45+
function averageNumbers (avg) {
46+
let sum = null;
47+
count = 0;
48+
avg.forEach( num1 => {
49+
sum += num1;
50+
count++;
51+
})
52+
if (sum == null){
53+
return sum;
54+
}
55+
sum = sum/count;
56+
return sum;
57+
}
58+
59+
1460
// Level 2: Array of strings
1561
const wordsArr = [
1662
'seat',
@@ -25,6 +71,11 @@ const wordsArr = [
2571
'palace'
2672
];
2773

74+
function averageWordLength(avg){
75+
let sumOfWords = null;
76+
let count = 0;
77+
avg.forEach
78+
}
2879
// Iteration #5: Unique arrays
2980
const wordsUnique = [
3081
'crab',

0 commit comments

Comments
 (0)