Last active
May 12, 2017 18:11
-
-
Save isijara/5de116716c55d1621c5641ceb6003616 to your computer and use it in GitHub Desktop.
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
let validCard = (card = '') => { | |
card = card.replace(/\s/g, '').split('').reverse().join(''); | |
let total = Number(card[0]); | |
for(let i = 1; i < card.length; i++) { | |
let digit = card[i]; | |
if(i % 2 == 1) { | |
digit = digit * 2; | |
if(digit > 9) { | |
let values = (digit + "").split(''); | |
digit = Number(values[0]) + Number(values[1]); | |
} | |
} | |
total += Number(digit); | |
} | |
return (total % 10) == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment