Created
November 4, 2016 11:10
-
-
Save davidhuser/97d0b79750b95e3565bfe0ad763cda4d to your computer and use it in GitHub Desktop.
Swiss ESR Checkdigit calculation (Prüfziffer)
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
// 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
see https://dnando.github.io/blog/2014/09/23/check-digit-computation-swiss-pay-slips/