← Back to challenges

Digits Sum Root

JavaScriptHardnumbersrecursionstringsmath

Instructions

Create a function that takes a number and returns one digit that is the result of summing all the digits of the input number. When the sum of the digits consists of more than one digit, repeat summing until you get one digit.

Examples

rootDigit(123) ➞ 6
// 1 + 2 + 3 = 6

rootDigit(999888777) ➞ 9

rootDigit(1238763636555555555555) ➞ 6

Notes

Recursion is allowed.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.