-
-
Save thg303/0955b9baf923b679372866abf3d67af7 to your computer and use it in GitHub Desktop.
تولید کننده کد ملی در جاوا اسکریپت
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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