loading...

re: Solving the Digital Root Algorithm using JavaScript VIEW POST

FULL DISCUSSION
 

function F_iRoot(P_sz0){
var sz0 = "" + P_sz0;
var iLen = sz0.length;
var iNum;
var ch;
var iSum = 0;
for (var i=0; i < iLen; i++) {
ch = sz0.charCodeAt(i);
iNum = ch - 48; // '0' = 0x30 = 48
iSum += iNum;
} /* for /
if (iSum > 9) {
iSum = F_iRoot(iSum);
} /
if /
return(iSum);
} /
F_iRoot */

code of conduct - report abuse