Created
November 16, 2017 18:19
-
-
Save iampeterbanjo/d08162323b8af03397b3e20f1a80211d to your computer and use it in GitHub Desktop.
Math for testing numbers divisible by 13
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
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