Skip to content

Commit

Permalink
Issue danthareja#1 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourav-Kumar-bit committed Dec 23, 2023
1 parent 97e1d5f commit 6aad2b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
34 changes: 8 additions & 26 deletions src/calculator.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
exports._check = () => {
// DRY up the codebase with this function
// First, move the duplicate error checking code here
// Then, invoke this function inside each of the others
// HINT: you can invoke this function with exports._check()
};

exports.add = (x, y) => {
exports._check = (x, y) => {
if (typeof x !== 'number') {
throw new TypeError(`${x} is not a number`);
}
if (typeof y !== 'number') {
throw new TypeError(`${y} is not a number`);
}
};

exports.add = (x, y) => {
exports._check(x, y);
return x + y;
};

exports.subtract = (x, y) => {
if (typeof x !== 'number') {
throw new TypeError(`${x} is not a number`);
}
if (typeof y !== 'number') {
throw new TypeError(`${y} is not a number`);
}
exports._check(x, y)
return x - y;
};

exports.multiply = (x, y) => {
if (typeof x !== 'number') {
throw new TypeError(`${x} is not a number`);
}
if (typeof y !== 'number') {
throw new TypeError(`${y} is not a number`);
}
exports._check(x, y)
return x * y;
};

exports.divide = (x, y) => {
if (typeof x !== 'number') {
throw new TypeError(`${x} is not a number`);
}
if (typeof y !== 'number') {
throw new TypeError(`${y} is not a number`);
}
exports._check(x, y)
return x / y;
};

Expand Down
2 changes: 1 addition & 1 deletion src/calculator.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-expressions */
const calculator = require('./calculator');

describe.skip('_check', () => {
describe('_check', () => {
beforeEach(() => {
sinon.spy(calculator, '_check');
});
Expand Down

0 comments on commit 6aad2b4

Please sign in to comment.