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.119 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.118 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.117 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.116 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.115 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.114 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.113 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.111 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.110 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.109 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.108 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.107 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.106 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.105 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.104 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.103 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.102 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.101 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.100 tracks/javascript/exercises/isbn-verifier/example.js
trackler-2.2.1.99 tracks/javascript/exercises/isbn-verifier/example.js