Skip to content

Instantly share code, notes, and snippets.

@DC3
Forked from zhuangya/id.coffee
Created June 22, 2020 09:42
Show Gist options
  • Save DC3/d3e9f066f23852af5d0eee82939029f9 to your computer and use it in GitHub Desktop.
Save DC3/d3e9f066f23852af5d0eee82939029f9 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