Last active
November 17, 2022 15:22
-
-
Save yhau1989/3afa1e8ef6504f1af5f6cf79c190f8c3 to your computer and use it in GitHub Desktop.
Mod 11 Javsscript
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://es.wikipedia.org/wiki/C%C3%B3digo_de_control | |
const mod11 = (text: string) => { | |
const items = text.split("").reverse() | |
let weigHing = 2 | |
let acum = 0 | |
items.forEach((item: string): void => { | |
acum += Number.parseInt(item) * weigHing | |
weigHing = weigHing == 7 ? 2 : weigHing + 1 | |
}) | |
const mod = acum % 11 | |
const checkDigit = 11 - mod | |
if (checkDigit == 10) return "K" //Chile 🇨🇱 | |
if (checkDigit == 11) return 0 | |
return checkDigit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment