Skip to content

Instantly share code, notes, and snippets.

@lydell
Created September 17, 2021 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydell/9b6692ec8246e1064ce423a521c1b497 to your computer and use it in GitHub Desktop.
Save lydell/9b6692ec8246e1064ce423a521c1b497 to your computer and use it in GitHub Desktop.
Calculate the last digit of a Swedish personnummer – Note: don’t include `19` or `20` at the start!
check = s => { let v = s.split("").map((c, i) => { let d = Number(c); let m = i % 2 === 0 ? d * 2 : d; return m > 9 ? m - 9 : m }).reduce((a, b) => a + b, 0); return (10 - (v % 10)) % 10}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment