Skip to content

Instantly share code, notes, and snippets.

@gfortaine
Created March 10, 2017 13:27
Show Gist options
  • Save gfortaine/77be53cdd82dc65e53f7e9373ea65810 to your computer and use it in GitHub Desktop.
Save gfortaine/77be53cdd82dc65e53f7e9373ea65810 to your computer and use it in GitHub Desktop.
Sum of Digits / Digital Root
// @flow
const digital_root = (n: number): number =>
n < 10
? n
: digital_root(n.toString(10).split('').reduce((prev, curr) => prev + parseInt(curr, 10), 0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment