Skip to content

Commit f7ac75c

Browse files
committed
made changes per review
1 parent b881892 commit f7ac75c

8 files changed

Lines changed: 18 additions & 24 deletions

File tree

‎Sprint-1/fix/median.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ function calculateMedian(list) {
99
if (!Array.isArray(list)) {
1010
return null;
1111
}
12-
const arrCopy = [...list];
13-
const filteredNumbers = arrCopy.filter((num) => Number.isFinite(num));
12+
const filteredNumbers = list.filter((num) => Number.isFinite(num));
1413

1514
if (filteredNumbers.length === 0) {
1615
return null;

‎Sprint-1/implement/dedupe.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function dedupe(elements) {
33
return [];
44
}
55

6-
return elements.filter((item, index) => elements.indexOf(item) === index);
6+
return [...new Set(elements)];
77
}
88

99
module.exports = dedupe;

‎Sprint-1/implement/dedupe.test.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ const testCaseNoDuplicates = [
3333
expected: [2, 3, 4, 5, 6, 7],
3434
},
3535
];
36+
const result = dedupe(input);
37+
3638
testCaseNoDuplicates.forEach(({ input, expected }) => {
3739
test("given an array with no duplicates, return a copy of the array", () => {
3840
expect(dedupe(input)).toEqual(expected);
41+
expect(result).not.toBe(input);
3942
});
4043
});
4144

‎Sprint-1/implement/max.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function findMax(elements) {
66
return typeof number === "number";
77
});
88
if (elementLists.length === 0) {
9-
return undefined;
9+
return 0;
1010
}
1111
if (elementLists.length === 1) {
1212
return elementLists[0];
@@ -19,5 +19,4 @@ function findMax(elements) {
1919
}
2020
return max;
2121
}
22-
console.log(findMax([-1, 0, -2]));
2322
module.exports = findMax;

‎Sprint-1/implement/max.test.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ testCaseArrayWithNonNumberValues.forEach(({ input, expected }) => {
9696
// When passed to the max function
9797
// Then it should return the least surprising value given how it behaves for all other inputs
9898
const testCaseArrayWithOnlyNonNumberValues = [
99-
{ input: ["hello", "world"], expected: undefined },
100-
{ input: [null, undefined, true, false], expected: undefined },
101-
{ input: [{}, [], "test"], expected: undefined },
99+
{ input: ["hello", "world", "300"], expected: 0 },
100+
{ input: [null, undefined, true, false], expected: 0 },
101+
{ input: [{}, [], "test"], expected: 0 },
102102
];
103103
testCaseArrayWithOnlyNonNumberValues.forEach(({ input, expected }) => {
104104
test("given an array with only non-number values, returns undefined", () => {

‎Sprint-1/implement/sum.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
function sum(elements) {
2-
if (elements.length === 0) {
3-
return 0;
4-
}
52
const elementsList = elements.filter((element) => {
6-
return typeof element === "number";
3+
return (
4+
typeof element === "number" &&
5+
!Number.isNaN(element) &&
6+
Number.isFinite(element)
7+
);
78
});
89
if (elementsList.length === 1) {
910
return elementsList[0];

‎Sprint-1/implement/sum.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ testCaseNonNumerical.forEach(({ input, expected }) => {
7474
// Then it should return the least surprising value given how it behaves for all other inputs
7575
const testNonNumberValues = [
7676
{ input: ["hello", "world"], expected: 0 },
77-
{ input: [null, undefined], expected: 0 },
77+
{ input: [null, undefined, NaN, Infinity, -Infinity], expected: 0 },
7878
{ input: [true, false, "apple"], expected: 0 },
7979
{ input: [{}, "10", null], expected: 0 },
8080
{ input: ["apple", null, undefined, false], expected: 0 },

‎Sprint-1/refactor/includes.js‎

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

3-
//my comments
4-
//make a copy of the array
5-
//check if target is in the array
63
function includes(list, target) {
7-
const targetFoundInArr = [];
84
for (const li of list) {
95
if (li === target) {
10-
targetFoundInArr.push(li);
6+
return true;
117
}
128
}
13-
if (targetFoundInArr.length === 0) {
14-
return false;
15-
}
16-
if (targetFoundInArr.length >= 1) {
17-
return true;
18-
}
9+
10+
return false;
1911
}
2012
console.log(includes([1, 2, 3, 4, 55, 6, null, 6, 7], 6));
2113
module.exports = includes;

0 commit comments

Comments
 (0)