Skip to content

Commit 72491e9

Browse files
committed
Finished iteration ironhack-labs#3.
1 parent 085df56 commit 72491e9

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/functions-and-arrays.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,38 @@ function findLongestWord(words) {
1919
return words[0]
2020
} else if (words.length > 1) {
2121
words.sort(function (a, b) {
22-
if (a.length < b.length) return 1; // 1 here (instead of -1 for ASC)
23-
if (a.length > b.length) return -1; // -1 here (instead of 1 for ASC)
22+
if (a.length < b.length) return 1;
23+
if (a.length > b.length) return -1;
2424
if (a.length === b.length) return 0;
2525
});
2626
}
2727
return words[0]
2828
}
2929

3030
// Iteration #3: Calculate the sum
31-
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
32-
33-
function sumNumbers() { }
31+
// const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
32+
33+
function sumNumbers(numbers) {
34+
if (numbers.length === 0) {
35+
return 0
36+
} else if (numbers.length >= 1) {
37+
let sum = 0
38+
for (let i = 0; i < numbers.length; ++i)
39+
sum += numbers[i];
40+
return sum
41+
}
42+
}
3443

3544

3645

3746
// Iteration #3.1 Bonus:
38-
function sum() { }
47+
// const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
48+
49+
function sum(mixedArr) {
50+
51+
52+
}
53+
3954

4055

4156

0 commit comments

Comments
 (0)