Skip to content

Commit 5007c4b

Browse files
committed
added all tests to test, started mean.js but not finished
1 parent aa7da66 commit 5007c4b

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

prep/mean.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//a data structure is used to group data together. it is a collection of data which has functions which allow you to access and manipulate the data.
2+
//an array is a zero indexed collection of data that holds data in an ordered list.
3+
function calculateMean(list) {
4+
let total = 0;
5+
6+
for (const item of list) {
7+
total += item;
8+
}
9+
}
10+
11+
function calculateMedian(list) {
12+
const middleIndex = Math.floor(list.length / 2);
13+
const median = list.splice(middleIndex, 1)[0];
14+
15+
return median;
16+
}
17+
18+
calculateMean([10, 20, 30, 40, 50]);

prep/mean.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test("calculates the mean of a list of numbers", () => {
2+
const list = [3, 50, 7];
3+
const currentOutput = calculateMean(list);
4+
const targetOutput = 20;
5+
6+
expect(currentOutput).toEqual(targetOutput);
7+
});
8+
9+
test("calculates the median of a list of odd length", () => {
10+
const list = [10, 20, 30, 50, 60];
11+
const currentOutput = calculateMedian(list);
12+
const targetOutput = 30;
13+
14+
expect(currentOutput).toEqual(targetOutput);
15+
});
16+
17+
test("doesn't modify the input", () => {
18+
const list = [1, 2, 3];
19+
calculateMedian(list);
20+
21+
expect(list).toEqual([1, 2, 3]); // Note that the toEqual matcher checks the values inside arrays when comparing them - it doesn't use `===` on the arrays, we know that would always evaluate to false.
22+
});

prep/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "prep",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "mean.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"type": "commonjs",
13+
"devDependencies": {
14+
"jest": "^30.2.0"
15+
}
16+
}

0 commit comments

Comments
 (0)