Skip to content

Instantly share code, notes, and snippets.

@Amice13
Created December 27, 2020 14:18
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 Amice13/a81613916cc2be1b1bd498ea4271cd4f to your computer and use it in GitHub Desktop.
Save Amice13/a81613916cc2be1b1bd498ea4271cd4f to your computer and use it in GitHub Desktop.
Перевірка ІПН
const mult = [-1, 5, 7, 9, 4, 6, 10, 5, 7]
const sourceDate = new Date('1899-12-31')
const checkIPN = str => {
const daysSinceBirthday = parseInt(str.slice(0, 5))
let birthday = new Date(sourceDate).setDate(sourceDate.getDate() + daysSinceBirthday + 1)
birthday = new Date(birthday)
const sex = parseInt(str.slice(8,9)) % 2 === 0 ? 'Жінка' : 'Чоловік'
const numbers = str.slice(0,9).split('').map(el => parseInt(el))
const checkSum = numbers.reduce((acc, val, i) => acc + val * mult[i], 0) % 11 % 10
const result = parseInt(str.slice(9, 10)) === checkSum
return { birthday, sex, result }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment