Skip to content

Instantly share code, notes, and snippets.

@zhuangya
Created March 26, 2012 05:35
Show Gist options
  • Save zhuangya/2203189 to your computer and use it in GitHub Desktop.
Save zhuangya/2203189 to your computer and use it in GitHub Desktop.
ID card verify
verify = (idcard) ->
factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
mask = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
idcard[idcard.length - 1] is mask[((x * factor[i] for x, i in idcard[0...idcard.length - 1]).reduce (x, y) -> x + y) % mask.length].toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment