Created
March 10, 2017 13:27
-
-
Save gfortaine/77be53cdd82dc65e53f7e9373ea65810 to your computer and use it in GitHub Desktop.
Sum of Digits / Digital Root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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