Created
August 11, 2022 16:45
-
-
Save josecarneiro/10c7f1941e43321cdaf65ff10814a5d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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