Sha256: 8294af443544921c35038ae7e7df4e461f46db0fde1df83612d2a01c09881a42

Contents?: true

Size: 470 Bytes

Versions: 121

Compression:

Stored size: 470 Bytes

Contents

'use strict';

function ISBN(isbn) {
  this.isbn = isbn.replace(/-/g, '');

  this.isValid = function () {
    if (!this.isbn.match(/^(\d{9}[\dX])$/)) {
      return false;
    }

    var digits = this.isbn.split('');
    if (digits[9] === 'X') {
      digits[9] = 10;
    }

    var sum = digits.reduce(function (total, current, index) {
      return total + ((10 - index) * parseInt(current, 10));
    }, 0);

    return sum % 11 === 0;
  };
}

module.exports = ISBN;

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.179 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.178 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.177 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.176 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.175 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.174 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.173 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.172 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.171 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.170 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.169 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.167 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.166 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.165 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.164 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.163 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.162 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.161 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.160 tracks/javascript/exercises/isbn-verifier/example.js