Created
August 20, 2019 22:26
-
-
Save anthony17guty/ac9725f40284d946ce9591bf5762cba1 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 validarCedula(cedula){ | |
let numero | |
let sumaImpares = 0; | |
let sumaPares = 0; | |
let sumaTotal = 0; | |
let validador= 0; | |
let codigoProvincia = cedula.substrimg(0,2); | |
if (codigoProvincia < 1 || codigoProvincia>24) | |
return false; | |
for (let i = 0; i< 10;i+=2){ | |
if(numero[i]*2>9){ | |
sumaImpares += (numero[i]*2)-9; | |
}else{ | |
sumaImpares += numero [i]*2; } | |
} | |
} | |
for (let i = 1;i <9;i +=2){ | |
sumaPares+= numero [i]*1; | |
} | |
sumaTotal= sumaImpares + sumaPares; | |
validador =sumaTotal % 10; | |
if (validador == 0){ | |
if (validador == numero [numero.length-1]){ | |
return true; | |
} | |
} | |
if(10 - validador == numero [numero.length -1]) { | |
return true; | |
} | |
console.log(validarCedula(1752290013)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment