My assumption is that the return in the first part of the if statement would break the function and return n, however it keeps giving undefined. If I console.log n it gives me the correct thing. Am I missing something??
Thanks everybody
function digital_root(n) {
if(n.toString().length === 1){
console.log(n)
return true;
}else{
var digits = (""+n).split("");
thing = digits.reduce((a, b) => Number(a) + Number(b), 0);
digital_root(thing)
}
}
digital_root(942)