Last active
October 11, 2022 19:41
-
-
Save gabrielrbarbosa/c93d5f3ca2a689d1bb2c4ca9dd25c70f to your computer and use it in GitHub Desktop.
Dígito Verificador Inscrição Estadual - MG
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
| //https://www.4devs.com.br/gerador_de_inscricao_estadual | |
| function weightCalculator(ie) { | |
| let weights = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]; | |
| let weights2 = [3, 2, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]; | |
| let base = ""; | |
| let base2 = 0, soma = 0; | |
| let block = ie.toString().split(""); | |
| block.splice(3, 0, "0"); | |
| for (let i = 0; i < block.length; i++) base += (weights[i] * block[i]).toString(); | |
| for (let char of base) soma += parseInt(char); | |
| block.push((Math.ceil(soma / 10) * 10 - soma).toString()); | |
| block.splice(3, 1); | |
| for (let i = 0; i < block.length; i++) base2 += weights2[i] * block[i]; | |
| block.push((11 - (base2 % 11)).toString()); | |
| return block.join().replace(/,/g, ""); | |
| } | |
| weightCalculator('79470492139'); //7947049213947 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment