Skip to content

Commit 31ed2a8

Browse files
committed
add solution ironhack-labs#3.1
1 parent 5208cdd commit 31ed2a8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/functions-and-arrays.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,27 @@ function sumNumbers(input) {
3434
}
3535

3636
// Iteration #3.1 Bonus:
37-
function sum() {}
37+
function sum(input) {
38+
let normalizedArr = [];
39+
40+
for (let element of input) {
41+
switch (typeof element) {
42+
case 'boolean':
43+
normalizedArr.push(element ? 1 : 0);
44+
break;
45+
case 'string':
46+
normalizedArr.push(element.length);
47+
break;
48+
case 'number':
49+
normalizedArr.push(element);
50+
break;
51+
default:
52+
throw "Unsupported data type sir or ma'am";
53+
}
54+
}
55+
56+
return sumNumbers(normalizedArr);
57+
}
3858

3959
// Iteration #4: Calculate the average
4060
// Level 1: Array of numbers

0 commit comments

Comments
 (0)