Skip to content

Commit dab9188

Browse files
committed
added a code that throws an error when a non number value is in the array
1 parent 49baa11 commit dab9188

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎Sprint-1/implement/sum.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
function sum(elements) {
2+
for (const num of elements) {
3+
if (typeof num !== "number") {
4+
throw new Error("sum requires an array of numbers");
5+
}
6+
}
27
let total = 0;
38
for (const num of elements) {
49
total += num;

0 commit comments

Comments
 (0)