Skip to content

Instantly share code, notes, and snippets.

@yhau1989
Last active November 17, 2022 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhau1989/3afa1e8ef6504f1af5f6cf79c190f8c3 to your computer and use it in GitHub Desktop.
Save yhau1989/3afa1e8ef6504f1af5f6cf79c190f8c3 to your computer and use it in GitHub Desktop.
Mod 11 Javsscript
//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