Skip to content

Instantly share code, notes, and snippets.

@dennyjohnk
Created February 11, 2022 04:46
Show Gist options
  • Save dennyjohnk/d610e10563079fd01cbce2dada7ebd6e to your computer and use it in GitHub Desktop.
Save dennyjohnk/d610e10563079fd01cbce2dada7ebd6e to your computer and use it in GitHub Desktop.
const digitalRoot = (n) => {
let numToString = n.toString();
let sum = 0;
for(let i = 0; i < numToString.length; i++){
sum += parseInt(numToString[i]);
}
if(sum > 9) {
return digitalRoot(sum);
}
console.log(sum);
}
digitalRoot(3898);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment