Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement_check #2230

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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