ISBN-10 identifiers are ten digits. The first nine digits are on the range 0 to 9. The last digit can be either on the range 0 to 9 or the letter 'X' used to indicate a value of 10.
For an ISBN-10 to be valid, the sum of the digits multiplied by their position has to equal zero modulo 11. For example, the ISBN-10: 1112223339 is valid because:
(((1*1)+(1*2)+(1*3)+(2*4)+(2*5)+(2*6)+(3*7)+(3*8)+(3*9)+(9*10)) % 11) == 0
Create the function validISBN10()
to return true if and only if the input is a valid ISBN-10 Identifier.
Examples
validISBN10('1293000000'), true
validISBN10('048665088X'), true
validISBN10('1234512345'), false
validISBN10('1293') , false
Tests
validISBN10('1112223339')
validISBN10('X123456788')
validISBN10('1234512345')
Good luck!
This challenge comes from nklein on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!