Created
May 13, 2016 15:31
-
-
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.
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 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