Created
May 25, 2024 19:54
-
-
Save Luisgustavom1/3f26a639e5f0c4a8260c52107e4a0453 to your computer and use it in GitHub Desktop.
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(n) { | |
if (n < 10) { | |
return n; | |
} | |
let nu = n | |
let s = 0 | |
while(nu > 0) { | |
const r = nu % 10 | |
s += r | |
nu = (nu - r) / 10 | |
} | |
return digitalRoot(s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment