We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5208cdd commit 31ed2a8Copy full SHA for 31ed2a8
src/functions-and-arrays.js
@@ -34,7 +34,27 @@ function sumNumbers(input) {
34
}
35
36
// Iteration #3.1 Bonus:
37
-function sum() {}
+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
48
+ case 'number':
49
+ normalizedArr.push(element);
50
51
+ default:
52
+ throw "Unsupported data type sir or ma'am";
53
+ }
54
55
56
+ return sumNumbers(normalizedArr);
57
+}
58
59
// Iteration #4: Calculate the average
60
// Level 1: Array of numbers
0 commit comments