Skip to content

Instantly share code, notes, and snippets.

@currentcreative
Forked from johnstew/digitalroot.js
Created November 12, 2016 06:24
Show Gist options
  • Save currentcreative/d7c8c16d2c049f66f8efc7ff98a649c5 to your computer and use it in GitHub Desktop.
Save currentcreative/d7c8c16d2c049f66f8efc7ff98a649c5 to your computer and use it in GitHub Desktop.
JS Digital Root
function root(num){
var total = 0;
if(num.toString().length == 1){
var iNum = parseInt(num);
return iNum;
}else{
num.toString().split("").forEach( function(value){
var iValue = parseInt(value);
return total += iValue;
});
return root(total);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment