Skip to content

Instantly share code, notes, and snippets.

@iampeterbanjo
Created November 16, 2017 18:19
Show Gist options
  • Save iampeterbanjo/d08162323b8af03397b3e20f1a80211d to your computer and use it in GitHub Desktop.
Save iampeterbanjo/d08162323b8af03397b3e20f1a80211d to your computer and use it in GitHub Desktop.
Math for testing numbers divisible by 13
var isDivisibleBy13 = function(test) {
if (Math.abs(test) === 13 || test % 13 === 0) {
return true;
}
var lastDigit = +String(number).slice(-1),
remainingDigits = +String(test).slice(0, -1);
if (test >= 13 && (remainingDigits - (lastDigit * 9)) % 13 === 0) {
return isDivisibleBy13(remainingDigits);
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment