Skip to content

Instantly share code, notes, and snippets.

@lissdy
Last active December 17, 2017 14:38
Show Gist options
  • Save lissdy/f7cdacd00d096a0ee068c00aeadb9304 to your computer and use it in GitHub Desktop.
Save lissdy/f7cdacd00d096a0ee068c00aeadb9304 to your computer and use it in GitHub Desktop.
CodeWar: Sum of Digits / Digital Root
function digital_root(n) {
if (n < 10)
return n;
return digital_root(n.toString().split('').reduce(function(acc, d) {
return acc + + d;
}, 0));;
}
console.log(digital_root(233412))
def digital_root(n):
return n if n < 10 else digital_root(sum(map(int,str(n))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment