function digital_root(n) {
let res = [];
function getResult(num) {
let result = num.toString().split('').reduce((sum, current) => {
let count = +sum + +current;
if(count.length > 1) getResult(count);
return count;
});
return result;
}
return getResult(n);
}
const digital_root = num => num > 9
? digital_root([...`${num}`].reduce((acc, n) => acc + +n, 0))
: num;