off by one in formatISBN
This commit is contained in:
parent
8a96a0a095
commit
0b7beec62d
1 changed files with 2 additions and 2 deletions
|
@ -653,13 +653,13 @@ Ox.formatISBN = function(isbn, length) {
|
||||||
var ret = '';
|
var ret = '';
|
||||||
function getCheckDigit(isbn) {
|
function getCheckDigit(isbn) {
|
||||||
var mod = isbn.length == 10 ? 11 : 10
|
var mod = isbn.length == 10 ? 11 : 10
|
||||||
return (mod - Ox.sum(
|
return (Ox.mod(mod - Ox.sum(
|
||||||
isbn.slice(0, -1).split('').map(function(digit, index) {
|
isbn.slice(0, -1).split('').map(function(digit, index) {
|
||||||
return isbn.length == 10
|
return isbn.length == 10
|
||||||
? parseInt(digit) * (10 - index)
|
? parseInt(digit) * (10 - index)
|
||||||
: parseInt(digit) * (index % 2 == 0 ? 1 : 3);
|
: parseInt(digit) * (index % 2 == 0 ? 1 : 3);
|
||||||
})
|
})
|
||||||
) % mod + '').replace('10', 'X');
|
), mod) + '').replace('10', 'X');
|
||||||
}
|
}
|
||||||
isbn = isbn.toUpperCase().replace(/[^\dX]/g, '');
|
isbn = isbn.toUpperCase().replace(/[^\dX]/g, '');
|
||||||
if (isbn.length == 10) {
|
if (isbn.length == 10) {
|
||||||
|
|
Loading…
Reference in a new issue