Sha256: e72e3f508510a83f91f4167423aaa3ba319c97f8cfed0198b9aeebf9454cdf8d
Contents?: true
Size: 497 Bytes
Versions: 59
Compression:
Stored size: 497 Bytes
Contents
class ISBN { isbn: string constructor(isbn: string) { this.isbn = isbn.replace(/-/g, '') } isValid() { if (!this.isbn.match(/^(\d{9}[\dxX])$/)) { return false } const digits = [...this.isbn] if (digits[9].match(/[xX]/)) { digits[9] = '10' } const sum = digits.reduce((acc, value, index) => acc + ((10 - index) * parseInt(value, 10)), 0) return sum % 11 === 0 } } export default ISBN
Version data entries
59 entries across 59 versions & 1 rubygems