Last active
April 1, 2016 15:19
-
-
Save oscarmorrison/0d7a4a1d0c3fc9e3b5dff506f50b28fe to your computer and use it in GitHub Desktop.
Credit Card CheckSum Javascript
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 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