Skip to content

Commit

Permalink
Resolve Issue danthareja#1 - Dry up the database
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJuneau committed Mar 22, 2018
1 parent bad0f18 commit df35aaf
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,47 +1,30 @@
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) => {
// Check that x and y are numbers, throw an error if one or more aren't.
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 df35aaf

Please sign in to comment.