Skip to content

Commit

Permalink
Merge pull request #126 from LavrL/master
Browse files Browse the repository at this point in the history
Fixed issue #1
  • Loading branch information
dantharejabot authored Feb 13, 2018
2 parents bad0f18 + 8a5acbe commit a55ecdd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
35 changes: 9 additions & 26 deletions src/calculator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
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`);
}
Expand All @@ -15,33 +8,23 @@ exports.add = (x, y) => {
return x + y;
};

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 a55ecdd

Please sign in to comment.