Skip to content

Instantly share code, notes, and snippets.

@genediazjr
Created May 9, 2019 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genediazjr/b74df25f2dc8e468265a9a720d711208 to your computer and use it in GitHub Desktop.
Save genediazjr/b74df25f2dc8e468265a9a720d711208 to your computer and use it in GitHub Desktop.
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