Created
March 17, 2020 13:05
-
-
Save aire-con-gas/bf3ef71cc0d954d35f2fc87f409f0f54 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 digital_root(n) { | |
// ... | |
function sum_roots(m) { | |
let rootArr = []; | |
let currentNum = m; | |
do { | |
rootArr.push(currentNum % 10); | |
currentNum = Math.trunc(currentNum / 10); | |
} while (currentNum >= 1) | |
return rootArr.reduce((acc, val) => acc + val, 0); | |
} | |
let result = n; | |
while(result > 10) { | |
result = sum_roots(result); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment