Skip to content

Commit 5af7258

Browse files
committed
Complete: Iteration ironhack-labs#3.2 Bonus
1 parent 0fb5469 commit 5af7258

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/functions-and-arrays.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,25 @@ function sumNumbers(numbers) {
3232

3333

3434

35-
// Iteration #3.1 Bonus:
36-
function sum() {}
35+
// Iteration #3.2 Bonus:
36+
const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10, {}];
37+
38+
function sum(mixedArr) {
39+
let sum = 0;
40+
for ( let entry of mixedArr ) {
41+
42+
if ( typeof entry === typeof [] || typeof entry === typeof {} ) {
43+
return Error("Unsupported data type sir or ma'am")
44+
} else {
45+
sum += typeof entry === typeof '' ? Number(entry.length) : Number(entry)
46+
}
47+
48+
}
49+
return sum;
50+
}
51+
console.log( sum([mixedArr]) );
52+
53+
// should return: 57
3754

3855

3956

0 commit comments

Comments
 (0)