Skip to content

Commit 64f84d9

Browse files
committed
fixed issues after the feedback 2
1 parent 0448c28 commit 64f84d9

6 files changed

Lines changed: 70 additions & 18 deletions

File tree

Sprint-1/fix/median.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function calculateMedian(list) {
2323
median = (sortedArray[middleIndex - 1] + sortedArray[middleIndex]) / 2;
2424
else median = sortedArray[middleIndex];
2525

26-
if (median === null) throw new Error("Median can't be null");
2726
return median;
2827
}
2928

Sprint-1/implement/dedupe.test.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("dedupe", () => {
1616
// Then it should return an empty array
1717
it("given an empty array it should return an empty array", () => {
1818
const array = [];
19-
dedupeArray = dedupe(array);
19+
const dedupeArray = dedupe(array);
2020
expect(dedupeArray).toEqual([]);
2121
});
2222

@@ -51,8 +51,25 @@ describe("dedupe", () => {
5151
// Given an input value that is not array could be null or undefined or just a number or string
5252
// When passed to the dedupe function
5353
// Then it should thrown an error
54-
[null, 930, "just a string", undefined, {}].forEach((val) =>
55-
it("throw an error if the input is not an array", () =>
56-
expect(() => dedupe(val)).toThrow(val + " is not an array"))
57-
);
54+
test("should thrown an error if the input is null", () => {
55+
expect(() => dedupe(null)).toThrow(null + " is not an array");
56+
});
57+
58+
test("should thrown an error if the input is a number", () => {
59+
const number = 123;
60+
expect(() => dedupe(number)).toThrow(number + " is not an array");
61+
});
62+
test("should thrown an error if the input is a string", () => {
63+
const string = "this is a string";
64+
expect(() => dedupe(string)).toThrow(string + " is not an array");
65+
});
66+
67+
test("should thrown an error if the input is undefined", () => {
68+
expect(() => dedupe(undefined)).toThrow(undefined + " is not an array");
69+
});
70+
71+
test("should thrown an error if the input is an object", () => {
72+
const emptyObject = {};
73+
expect(() => dedupe(emptyObject)).toThrow(emptyObject + " is not an array");
74+
});
5875
});

Sprint-1/implement/max.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function findMax(array) {
22
if (!Array.isArray(array)) throw new Error(array + " is not an array");
3-
let numbersArray = array.filter((value) => typeof value === "number");
3+
const numbersArray = array.filter((value) => typeof value === "number");
44
return Math.max(...numbersArray);
55
}
66

Sprint-1/implement/max.test.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,28 @@ describe("findMax", () => {
108108
// Given an input that is not array could be null or undefined or just a number or string
109109
// When passed to the findMax function
110110
// Then it should thrown an error
111-
[null, 930, "just a string", undefined, {}].forEach((val) =>
112-
it("throw an error if the input is not an array", () =>
113-
expect(() => findMax(val)).toThrow(val + " is not an array"))
114-
);
111+
112+
test("should thrown an error if the input is null", () => {
113+
expect(() => findMax(null)).toThrow(null + " is not an array");
114+
});
115+
116+
test("should thrown an error if the input is a number", () => {
117+
const number = 980;
118+
expect(() => findMax(number)).toThrow(number + " is not an array");
119+
});
120+
test("should thrown an error if the input is a string", () => {
121+
const string = "just a string";
122+
expect(() => findMax(string)).toThrow(string + " is not an array");
123+
});
124+
125+
test("should thrown an error if the input is undefined", () => {
126+
expect(() => findMax(undefined)).toThrow(undefined + " is not an array");
127+
});
128+
129+
test("should thrown an error if the input is an object", () => {
130+
const emptyObject = {};
131+
expect(() => findMax(emptyObject)).toThrow(
132+
emptyObject + " is not an array"
133+
);
134+
});
115135
});

Sprint-1/implement/sum.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
function sum(array) {
22
if (!Array.isArray(array)) throw new Error(array + " is not an array");
33
let numbersArray = array.filter((value) => typeof value === "number");
4-
let initialValue = 0;
5-
let sum = numbersArray.reduce(
4+
const sum = numbersArray.reduce(
65
(accumulator, currentValue) => accumulator + currentValue,
7-
initialValue
6+
0
87
);
98
return sum;
109
}

Sprint-1/implement/sum.test.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,25 @@ describe("sum", () => {
7979
// Given an input value that is not array could be null or undefined or just a number or string
8080
// When passed to the sum function
8181
// Then it should thrown an error
82-
[null, 930, "just a string", undefined, {}].forEach((val) =>
83-
it("throw an error if the input is not an array", () =>
84-
expect(() => sum(val)).toThrow(val + " is not an array"))
85-
);
82+
test("should thrown an error if the input is null", () => {
83+
expect(() => sum(null)).toThrow(null + " is not an array");
84+
});
85+
86+
test("should thrown an error if the input is a number", () => {
87+
const number = 123;
88+
expect(() => sum(number)).toThrow(number + " is not an array");
89+
});
90+
test("should thrown an error if the input is a string", () => {
91+
const string = "this is a string";
92+
expect(() => sum(string)).toThrow(string + " is not an array");
93+
});
94+
95+
test("should thrown an error if the input is undefined", () => {
96+
expect(() => sum(undefined)).toThrow(undefined + " is not an array");
97+
});
98+
99+
test("should thrown an error if the input is an object", () => {
100+
const emptyObject = {};
101+
expect(() => sum(emptyObject)).toThrow(emptyObject + " is not an array");
102+
});
86103
});

0 commit comments

Comments
 (0)