Skip to content

Instantly share code, notes, and snippets.

@elliot
Created August 23, 2011 07:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliot/1164554 to your computer and use it in GitHub Desktop.
Save elliot/1164554 to your computer and use it in GitHub Desktop.
Luhn Algorithm in CoffeeScript
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
@dumorango
Copy link

Tks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment