Skip to content

Instantly share code, notes, and snippets.

@alvin-milton
Created May 13, 2016 15:31
Show Gist options
  • Save alvin-milton/b912ea285682af445177c7f44d25ea3d to your computer and use it in GitHub Desktop.
Save alvin-milton/b912ea285682af445177c7f44d25ea3d to your computer and use it in GitHub Desktop.
Write a function accepts numbers as strings and adds them. Return them as strings.
function validateInput(a) {
var valid = a >= 0 ? a : false;
return valid;
}
function doIt(a, b) {
var arr = [],
i = 0,
x = parseInt(a, 10),
y = parseInt(b, 10),
sum = 0;
arr.push(x);
arr.push(y);
for(i; i<=arr.length; i++) {
if (validateInput(arr[i])) {
sum += arr[i];
}
}
console.log(sum.toString());
}
doIt('89234025487252189', '20342034982340220341');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment