Digits Sum Root

Published by Deep Xavier in

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

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

digitRoot(999888777L) ➞ 9

digitRoot(1238763636555555555L) ➞ 9

Notes

Recursion is allowed.

Watch a quick demo on how Edabit works.