Skip to content

Instantly share code, notes, and snippets.

@davidhuser
Created November 4, 2016 11:10
Show Gist options
  • Save davidhuser/97d0b79750b95e3565bfe0ad763cda4d to your computer and use it in GitHub Desktop.
Save davidhuser/97d0b79750b95e3565bfe0ad763cda4d to your computer and use it in GitHub Desktop.
Swiss ESR Checkdigit calculation (Prüfziffer)
// calculates the checkdigit number of Swiss Invoice codes
function calc_digit(number) {
var table = [0, 9, 4, 6, 8, 2, 7, 1, 3, 5];
var uebertrag = 0;
for (var i = 0; i < number.length; i++) {
c = parseInt(number.substring(i, i + 1), 10);
index = (uebertrag + c) % 10;
uebertrag = table[index];
}
return (10 - uebertrag) % 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment