Sum of Digits of a Positive Integer

Published by Werdna in

An instructor has given her student an assignment to calculate the sum of the digits of a positive integer using recursion.The student came up with the solution but the solution does not seem to be correct. Help her fix the error.

Examples

sumDigit(111) ➞ 3
// 1 + 1 + 1 = 3

sumDigit(222) ➞ 6
// 2 + 2 + 2 = 6

sumDigit(333) ➞ 9
// 3 + 3 + 3 = 9

Notes

Input is a positive integer.

Watch a quick demo on how Edabit works.