Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save josecarneiro/10c7f1941e43321cdaf65ff10814a5d2 to your computer and use it in GitHub Desktop.
Save josecarneiro/10c7f1941e43321cdaf65ff10814a5d2 to your computer and use it in GitHub Desktop.
function sum(a, b) {
if (typeof a === 'undefined' && typeof b === 'undefined') {
return 0;
} else if (typeof b === 'undefined') {
return a + 0;
} else {
return a + b;
}
}
function subtract(a, b) {
if (typeof a === 'undefined' && typeof b === 'undefined') {
return 0;
} else if (typeof b === 'undefined') {
return a - 0;
} else {
return a - b;
}
}
function divide(a, b) {
if (b === 0) {
throw new Error('Cannot divide by 0');
} else {
return a / b;
}
}
function multiply(a, b) {
return a * b;
}
// The following is required to make unit tests work. Please ignore it.
module.exports = { sum, subtract, divide, multiply };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment