Skip to content

Commit b06cb19

Browse files
committed
Add mean calculation test
1 parent cd4c69f commit b06cb19

File tree

4 files changed

+4425
-0
lines changed

4 files changed

+4425
-0
lines changed

prep/mean.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function calculateMean(list) {
2+
const sum = list.reduce((acc, num) => acc + num, 0);
3+
return sum / list.length;
4+
}
5+
6+
module.exports = calculateMean;

prep/mean.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const calculateMean = require("./mean");
2+
3+
test("calculates the mean of a list of numbers", () => {
4+
const list = [3, 50, 7];
5+
const currentOutput = calculateMean(list);
6+
const targetOutput = 20;
7+
8+
expect(currentOutput).toEqual(targetOutput); // 20 is (3 + 50 + 7) / 3
9+
});

0 commit comments

Comments
 (0)