Created
June 12, 2017 18:39
-
-
Save BeKnowDo/784fef473e4cf77ccecaea5ea9521c90 to your computer and use it in GitHub Desktop.
Digital Root
This file contains hidden or 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
function digitalRoot(number) { | |
let lengthCheck = '' | |
const originalNumber = number | |
function add(a, b) { | |
this.a = parseInt(a) | |
this.b = parseInt(b) | |
return this.a + this.b | |
} | |
lengthCheck = originalNumber.toString().split('').reduce(add, 0) | |
return lengthCheck.toString().length > 1 ? digitalRoot(lengthCheck) : lengthCheck | |
} | |
console.clear() | |
console.log(digitalRoot(12345699999)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment