Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save charleslukes/c2d67c8e21ae14e6ff327bb760cce042 to your computer and use it in GitHub Desktop.
Save charleslukes/c2d67c8e21ae14e6ff327bb760cce042 to your computer and use it in GitHub Desktop.
addMethod.js
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