Created
June 27, 2024 13:03
-
-
Save alexsad/f654f2c898989b0e52f606301e3128f2 to your computer and use it in GitHub Desktop.
cpf validation
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 sumCPF = (cpf, digitos) => { | |
const sum = cpf | |
.split('') | |
.filter((...[,index]) => index < digitos) | |
.reduce((sum, curr, index) => sum + (curr * (1+digitos - index)), 0); | |
const total = (sum * 10) % 11; | |
return [10,11].includes(total) ? 0 : total; | |
} | |
sumCPF('62193597049', 9); //first digit verification | |
sumCPF('62193597049', 10); //second digit verification |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment