Skip to content

Instantly share code, notes, and snippets.

@BeKnowDo
Created June 12, 2017 18:39
Show Gist options
  • Save BeKnowDo/784fef473e4cf77ccecaea5ea9521c90 to your computer and use it in GitHub Desktop.
Save BeKnowDo/784fef473e4cf77ccecaea5ea9521c90 to your computer and use it in GitHub Desktop.
Digital Root
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