Skip to content

Commit

Permalink
Merge pull request #3 from tony-codecov/tony/test-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-codecov authored Nov 28, 2024
2 parents 66ebc17 + 624cb0b commit aee9c9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions flag1/mafs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ function divide(a, b) {
}
}

// function sum(...args) {
// return args.reduce((acc, curr) => acc + curr, 0);
// }
function sum(...args) {
if (args.length === 0) return 0;
return args.reduce((acc, curr) => acc + curr, 0);
}

module.exports = { add, subtract, multiply, divide };
module.exports = { add, subtract, multiply, divide, sum };
12 changes: 8 additions & 4 deletions flag1/mafs.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { add, subtract, multiply, divide } = require("./mafs");
const { add, subtract, multiply, divide, sum } = require("./mafs");

test("adds 1 + 2 to equal 3", () => {
expect(add(1, 2)).toBe(3);
Expand All @@ -20,6 +20,10 @@ test('divides 8 / 2 to equal 4', () => {
expect(divide(8, 2)).toBe(4);
});

// test('sums 1 + 2 + 3 + 4 to equal 10', () => {
// expect(sum(1, 2, 3, 4)).toBe(10);
// });
test('sums 1 + 2 + 3 + 4 to equal 10', () => {
expect(sum(1, 2, 3, 4)).toBe(10);
});

test('sums 1 + 2 + 3 + 4 to equal 10', () => {
expect(sum()).toBe(0);
});

0 comments on commit aee9c9d

Please sign in to comment.