Created
March 2, 2016 22:31
-
-
Save DanielFGray/184e7c2eb991c32f20cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function validISBN10(isbn) { | |
if(! /\d{9}[X0-9]/.test(isbn)) return false; | |
return isbn.split('').reduce((p, c, i) => { | |
return p + ((c == 'X') ? 10 : parseInt(c)) * ++i; | |
}, 0) % 11 == 0; | |
} | |
(function (func, cases, invert) { | |
cases.forEach(t => | |
console.log(func(t[0]) == t[1], `${func.name}(${t[0]}) == ${t[1]}`) | |
); | |
})(validISBN10, [ | |
[ '1112223339', true ], | |
[ '1234554321', true ], | |
[ '1234512345', false ], | |
[ '048665088X', true ] | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment