Created
August 23, 2011 07:24
-
-
Save elliot/1164554 to your computer and use it in GitHub Desktop.
Luhn Algorithm in CoffeeScript
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
validateLuhn = (number) -> | |
odd = true | |
sum = _(number.split '').reduceRight (total, digit) -> | |
digit = parseInt(digit) | |
digit *= 2 if (odd = !odd) | |
digit -= 9 if digit > 9 | |
total + digit | |
, 0 | |
sum % 10 == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tks!