Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sprint-1/implement/dedupe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ test("given an empty array, it returns an empty array", () => {
test("given an array with no duplicates", () => {
const input = [1, 2, 3, 4, 5];
const result = dedupe(input);
expect(result).toStrictEqual([1, 2, 3, 4, 5]);
expect(result).not.toBe([1, 2, 3, 4, 5]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax [1, 2, 3, 4, 5] always creates a new array.

On line 32, the statement is not checking if result and the array passed to dedupe() are different arrays.

expect(result).toEqual([1, 2, 3, 4, 5]);
});

// Given an array with strings or numbers
Expand Down
12 changes: 6 additions & 6 deletions Sprint-1/implement/sum.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function sum(elements) {
return elements.reduce((accumulator, currentValue) => {
if (typeof currentValue === "number" && Number.isFinite(currentValue)) {
return accumulator + currentValue;
}
return accumulator;
if (!Array.isArray(elements)) return null;

return elements.reduce((accumulator, n) => {
return typeof n === 'number' && !isNaN(n) ? accumulator + n : accumulator;
}, 0);
}
}


module.exports = sum;

Expand Down