Skip to content

Commit 45ac6f6

Browse files
Iteration ironhack-labs#3: Calculate the sum
1 parent 600f44b commit 45ac6f6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ function findLongestWord(arr) {
2525
return longestWord;
2626
}
2727

28-
findLongestWord(words);
29-
3028

3129
// Iteration #3: Calculate the sum
3230

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

33+
function sumArray (arr){
34+
let sum = 0
35+
if (arr.length >0){
36+
for(var i = 0; i < arr.length; i++){
37+
sum += arr[i];
38+
}
39+
}
40+
return sum;
41+
}
42+
3543
// Iteration #4: Calculate the average
3644
// Level 1: Array of numbers
3745
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

0 commit comments

Comments
 (0)