digital root function js
function digitalRoot(number) {
let sum = number
let arr = []
let reducer = (a,b) => parseInt(a) + parseInt(b)
if (sum > 9) {
arr = sum.toString().split("")
sum = arr.reduce(reducer)
console.log(sum)
}
}
---------- More Simple ---------------------
function digital_root(n) {
return (n - 1) % 9 + 1;
}