Skip to content

Instantly share code, notes, and snippets.

@mistadikay
Last active August 29, 2015 14:05
Show Gist options
  • Save mistadikay/7f22c3b22cd79fe55f18 to your computer and use it in GitHub Desktop.
Save mistadikay/7f22c3b22cd79fe55f18 to your computer and use it in GitHub Desktop.
function checkControlSumJuridical(value){
var code = value.split(''),
numericValue = +value,
x;
if ((numericValue < 30000000) || (numericValue > 60000000)){
x = code[0] + code[1] * 2 + code[2] * 3 + code[3] * 4 + code[4] * 5 + code[5] * 6 + code[6] * 7;
} else{
x = code[0] * 7 + code[1] + code[2] * 2 + code[3] * 3 + code[4] * 4 + code[5] * 5 + code[6] * 6;
}
x = x - (11 * Math.floor(x / 11));
if (x === 10){
if ((numericValue < 30000000) || (numericValue > 60000000)){
x = code[0] * 3 + code[1] * 4 + code[2] * 5 + code[3] * 6 + code[4] * 7 + code[5] * 8 + code[6] * 9;
} else{
x = code[0] * 9 + code[1] * 3 + code[2] * 4 + code[3] * 5 + code[4] * 6 + code[5] * 7 + code[6] * 8;
}
x = x - (11 * Math.floor(x / 11));
if (x === 10){
x = 0;
}
}
return +code[7] === x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment