Created
December 13, 2023 22:52
-
-
Save leandroandrade/5cd86764515129ab83e5da314ae70cad to your computer and use it in GitHub Desktop.
This file contains 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
const dig = (n1, n2, n3, n4) => { | |
const nums = n1.split("").concat(n2.split(""), n3.split("")); | |
if (n4 !== undefined){ | |
nums[9] = n4; | |
} | |
let x = 0; | |
for (let i = (n4 !== undefined ? 11:10), j = 0; i >= 2; i--, j++) { | |
x += parseInt(nums[j]) * i; | |
} | |
const y = x % 11; | |
return y < 2 ? 0 : 11 - y; | |
} | |
const aleatorio = () => { | |
const aleat = Math.floor(Math.random() * 999); | |
return ("" + aleat).padStart(3, '0'); | |
} | |
const gerarCpf = () => { | |
const num1 = aleatorio(); | |
const num2 = aleatorio(); | |
const num3 = aleatorio(); | |
const dig1 = dig(num1, num2, num3); | |
const dig2 = dig(num1, num2, num3, dig1); | |
// return `${num1}.${num2}.${num3}-${dig1}${dig2}`; | |
return `${num1}${num2}${num3}${dig1}${dig2}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment