Created
May 9, 2019 03:45
-
-
Save genediazjr/b74df25f2dc8e468265a9a720d711208 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
const isValidServiceId = (serviceId) => { | |
serviceId = `${serviceId}`; | |
while (serviceId.length < 10) { | |
serviceId = `0${serviceId}`; | |
} | |
const rootId = serviceId.slice(0, -1); | |
let sum = 0; | |
for (let i = 0, index = rootId.length + 1; i < rootId.length; i++, index--) { | |
sum += parseInt(rootId[i]) * index; | |
} | |
const value = (11 - sum % 11) % 11; | |
return serviceId[9] === (value === 10 ? 'X' : value); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment