DEV Community

Discussion on: Solving the Digital Root Algorithm using JavaScript

Collapse
 
khuongduybui profile image
Duy K. Bui

Can I cheat?

function d_root(num) {
  return (num % 9) || 9;
}
Enter fullscreen mode Exit fullscreen mode

:D

Collapse
 
athul7744 profile image
Athul Anil Kumar

Amazing intuition!

Collapse
 
keltroth profile image
Django Janny

What about d_root(0) ?

Collapse
 
pavi2410 profile image
Pavitra Golchha

I am really curious how do you know this?

Collapse
 
khuongduybui profile image
Duy K. Bui

I learnt it first as a math trick for children in Vietnam: to know if something is divisible by 9, you calculate its digitial root and see if the digital root is divisible by 9 (same goes for 3).

When I grew up, I was curious and tried to prove that mathematically, which is how I ended up with digitalRoot(num) = num % 9 (or 9 if divisible by 9) :D

Collapse
 
terkwood profile image
Felix Terkhorn

mathworld.wolfram.com/DigitalRoot....

Looking good in this corner of the thread!