Last active
December 17, 2017 14:38
-
-
Save lissdy/f7cdacd00d096a0ee068c00aeadb9304 to your computer and use it in GitHub Desktop.
CodeWar: Sum of Digits / 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 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