Skip to content

Commit 1cb5870

Browse files
committed
i have fixed issues following the feedback instructions
1 parent ae69f89 commit 1cb5870

7 files changed

Lines changed: 33 additions & 21 deletions

File tree

Sprint-1/fix/median.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function calculateMedian(list) {
1010
return null;
1111
}
1212
const numbersOnly = list.filter(item => typeof item === 'number');
13-
const sorted = [...numbersOnly].sort((a, b) => a - b);
13+
const sorted = numbersOnly.sort((a, b) => a - b);
1414

1515
if (sorted.length === 0) {
1616
return null;

Sprint-1/fix/median.test.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ describe("calculateMedian", () => {
1313
{ input: [1, 2, 3, 4], expected: 2.5 },
1414
{ input: [1, 2, 3, 4, 5, 6], expected: 3.5 },
1515
].forEach(({ input, expected }) =>
16-
it(`returns the median for [${input}]`, () => expect(calculateMedian(input)).toEqual(expected))
16+
it(`returns the median for [${input}]`, () =>
17+
expect(calculateMedian(input)).toEqual(expected))
1718
);
1819

1920
[
@@ -22,9 +23,10 @@ describe("calculateMedian", () => {
2223
{ input: [4, 2, 1, 3], expected: 2.5 },
2324
{ input: [6, 1, 5, 3, 2, 4], expected: 3.5 },
2425
{ input: [110, 20, 0], expected: 20 },
25-
{ input: [6, -2, 2, 12, 14], expected: 6},
26+
{ input: [6, -2, 2, 12, 14], expected: 6 },
2627
].forEach(({ input, expected }) =>
27-
it(`returns the correct median for unsorted array [${input}]`, () => expect(calculateMedian(input)).toEqual(expected))
28+
it(`returns the correct median for unsorted array [${input}]`, () =>
29+
expect(calculateMedian(input)).toEqual(expected))
2830
);
2931

3032
it("doesn't modify the input array [3, 1, 2]", () => {
@@ -33,8 +35,17 @@ describe("calculateMedian", () => {
3335
expect(list).toEqual([3, 1, 2]);
3436
});
3537

36-
[ 'not an array', 123, null, undefined, {}, [], ["apple", null, undefined] ].forEach(val =>
37-
it(`returns null for non-numeric array (${val})`, () => expect(calculateMedian(val)).toBe(null))
38+
[
39+
"not an array",
40+
123,
41+
null,
42+
undefined,
43+
{},
44+
[],
45+
["apple", null, undefined],
46+
].forEach((val) =>
47+
it(`returns null for non-numeric array (${val})`, () =>
48+
expect(calculateMedian(val)).toBe(null))
3849
);
3950

4051
[
@@ -45,6 +56,7 @@ describe("calculateMedian", () => {
4556
{ input: [3, "apple", 1, null, 2, undefined, 4], expected: 2.5 },
4657
{ input: ["banana", 5, 3, "apple", 1, 4, 2], expected: 3 },
4758
].forEach(({ input, expected }) =>
48-
it(`filters out non-numeric values and calculates the median for [${input}]`, () => expect(calculateMedian(input)).toEqual(expected))
59+
it(`filters out non-numeric values and calculates the median for [${input}]`, () =>
60+
expect(calculateMedian(input)).toEqual(expected))
4961
);
5062
});

Sprint-1/implement/dedupe.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ test.todo("given an empty array, it returns an empty array");
2525
// Given an array with strings or numbers
2626
// When passed to the dedupe function
2727
// Then it should remove the duplicate values, preserving the first occurence of each element
28+

Sprint-1/implement/max.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ test.todo("given an empty array, returns -Infinity");
4141
// Given an array with only non-number values
4242
// When passed to the max function
4343
// Then it should return the least surprising value given how it behaves for all other inputs
44+

Sprint-1/implement/sum.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
function sum(elements)
2-
{ let sum = 0;
3-
for (let i = 0; i < elements.length; i++) {
4-
if (typeof elements[i] === "number"){
5-
sum += elements[i];
6-
}
1+
function sum(elements) {
2+
let sum = 0;
3+
for (let i = 0; i < elements.length; i++) {
4+
if (Number.isFinite(elements[i])) {
5+
sum += elements[i];
76
}
8-
9-
return sum;
7+
}
8+
return sum;
109
}
1110

12-
13-
1411
module.exports = sum;

Sprint-1/implement/sum.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ test.todo("given an empty array, returns 0")
3434
// Given an array with only non-number values
3535
// When passed to the sum function
3636
// Then it should return the least surprising value given how it behaves for all other inputs
37+

Sprint-1/refactor/includes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Refactor the implementation of includes to use a for...of loop
22

33
function includes(list, target) {
4-
for (const element of list) {
5-
if (element === target) {
6-
return true;
7-
}
4+
for (const element of list) {
5+
if (element === target) {
6+
return true;
87
}
8+
}
99
return false;
1010
}
1111

0 commit comments

Comments
 (0)