0

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)

1 Answers1

0

You do not return in the recursion so that means it will return undefined.

return digital_root(thing)
epascarello
  • 204,599
  • 20
  • 195
  • 236