Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Last active April 1, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarmorrison/0d7a4a1d0c3fc9e3b5dff506f50b28fe to your computer and use it in GitHub Desktop.
Save oscarmorrison/0d7a4a1d0c3fc9e3b5dff506f50b28fe to your computer and use it in GitHub Desktop.
Credit Card CheckSum Javascript
function checksumCC(creditCardString){
sum = creditCardString
.split('')
.reverse()
.reduce(function(total, num, i){
num = parseInt(num, 10);
if(i%2 !== 0){
num *= 2;
if(num>9){
num -= 9;
}
}
return total + num;
}, 0);
return (sum%10 === 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment