Skip to content

Commit

Permalink
Merge pull request #122 from gkchan/master
Browse files Browse the repository at this point in the history
Implement _check
  • Loading branch information
dantharejabot authored Feb 12, 2018
2 parents bad0f18 + 12e991f commit 54b353b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
29 changes: 8 additions & 21 deletions src/calculator.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
exports._check = () => {
exports._check = (x, y) => {
// 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) => {
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 54b353b

Please sign in to comment.