From 0717c11d15b54a2ca692385e8189ab94801f511a Mon Sep 17 00:00:00 2001 From: LavrL Date: Tue, 13 Feb 2018 17:07:06 +0000 Subject: [PATCH 1/2] Fixed issue #1 --- src/calculator.js | 36 ++++++++++-------------------------- src/calculator.test.js | 2 +- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/calculator.js b/src/calculator.js index b46080e5..9e6665ea 100644 --- a/src/calculator.js +++ b/src/calculator.js @@ -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`); } @@ -15,33 +8,24 @@ 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; }; diff --git a/src/calculator.test.js b/src/calculator.test.js index d0f85ed6..3d6b7f74 100644 --- a/src/calculator.test.js +++ b/src/calculator.test.js @@ -1,7 +1,7 @@ /* eslint-disable no-unused-expressions */ const calculator = require('./calculator'); -describe.skip('_check', () => { +describe('_check', () => { beforeEach(() => { sinon.spy(calculator, '_check'); }); From 8a5acbea65e748c53f37260dfb92301bb9f4b30d Mon Sep 17 00:00:00 2001 From: LavrL Date: Tue, 13 Feb 2018 18:31:35 +0000 Subject: [PATCH 2/2] Fixed trailing space issue --- src/calculator.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/calculator.js b/src/calculator.js index 9e6665ea..f1ae76d8 100644 --- a/src/calculator.js +++ b/src/calculator.js @@ -8,14 +8,13 @@ exports._check = (x, y) => { return x + y; }; - exports.add = (x, y) => { exports._check(x, y); return x + y; }; exports.subtract = (x, y) => { - exports._check(x, y); + exports._check(x, y); return x - y; };