Skip to content

Commit 277854f

Browse files
author
Dmitry Ovsyanko
committed
+.modulus
1 parent 5591554 commit 277854f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/Check.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module.exports = class {
66
this.checkSumLength = checkSumLength
77
this.totalLength = totalLength
88

9+
this.modulus = 10; for (let i = 1; i < checkSumLength; i ++) this.modulus *= 10
10+
911
}
1012

1113
raise (s, o) {
@@ -54,11 +56,9 @@ module.exports = class {
5456

5557
this.process (str)
5658

57-
const {sum} = this; delete this.sum
58-
59-
return String (this.checkSumLength === 1 ? sum % 11 % 10 : sum % 101 % 100)
59+
const {sum, modulus} = this; delete this.sum
6060

61-
.padStart (this.checkSumLength, '0')
61+
return String (sum % (modulus + 1) % modulus).padStart (this.checkSumLength, '0')
6262

6363
}
6464

0 commit comments

Comments
 (0)