Skip to content

Commit d8b4b8b

Browse files
Merge pull request akshitagit#97 from garridorafa/master
Add a digital root math algorithms
2 parents e768008 + 3976f3b commit d8b4b8b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Maths/digital_root.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function digital_root (num){
2+
let i = 0;
3+
let num2 = num;
4+
let sum=0;
5+
while( num2 >= 1 ) {
6+
i++;
7+
num2 = num2/10;
8+
}
9+
while( i !== 0 ) {
10+
i=i-1;
11+
let mod = Math.floor(num/Math.pow(10,i));
12+
num = num % Math.pow(10,i)
13+
sum = sum + mod;
14+
}
15+
16+
if (sum < 10) {
17+
return sum;
18+
} else {
19+
return digital_root (sum);
20+
};
21+
}

0 commit comments

Comments
 (0)