Answers for "digital root function js"

0

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;
}
Posted by: Guest on October-12-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language