Skip to content

Instantly share code, notes, and snippets.

@thg303
Forked from Alireza2n/nationalCodeGenerator.py
Last active March 14, 2021 10:15
Show Gist options
  • Save thg303/0955b9baf923b679372866abf3d67af7 to your computer and use it in GitHub Desktop.
Save thg303/0955b9baf923b679372866abf3d67af7 to your computer and use it in GitHub Desktop.
تولید کننده کد ملی در جاوا اسکریپت
function generateNationalCode() {
let numbers = []
let sum = 0
for (let i = 10; i >= 2; i--) {
let j = Math.floor(Math.random() * 10)
numbers.push(j)
sum += j * i
}
const m = sum % 11
numbers.push(m < 2 ? m : 11 - m)
return numbers.join('')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment