Created
May 9, 2019 16:53
-
-
Save charleslukes/c2d67c8e21ae14e6ff327bb760cce042 to your computer and use it in GitHub Desktop.
addMethod.js
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 addNumber (...arg) { | |
let calculator = 0; | |
if(arg.length === 0){ | |
throw new Error('The input cannot be empty'); | |
} | |
for (let index = 0; index < arg.length; index++) { | |
if(typeof arg[index] !== 'number'){ | |
return 'Input must be a number'; | |
} | |
calculator += arg[index]; | |
} | |
return calculator; | |
} | |
module.exports = addNumber; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment