Skip to content

Commit e912e06

Browse files
committed
fix: ensure calculateMean validates input as an array of numbers
1 parent e94100e commit e912e06

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎Sprint-1/implement/mean.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ function calculateMean(list) {
55
if (list.length === 0) {
66
throw new Error("calculateMean requires a non-empty array");
77
}
8+
if (!list.every((item) => typeof item === "number")) {
9+
throw new Error("calculateMean requires an array of numbers");
10+
}
11+
let total = 0;
12+
for (const item of list) {
13+
total += item;
14+
}
15+
return total / list.length;
816
}
917

1018
module.exports = calculateMean;

0 commit comments

Comments
 (0)