Special Sum of an Array
Problem statement
You are given an integer array values whose elements are decimal digits.
First, add all elements of the array. While the sum contains more than one digit, replace it with the sum of its decimal digits.
Return the final single-digit value.
Function
specialSum(values: int[]) → intExamples
Example 1
values = [5,8,4,9]return = 8The array sum is 26. Its digit sum is 2 + 6 = 8, which is a single digit.
Example 2
values = [8,7,0,1,2]return = 9The array sum is 18, and 1 + 8 = 9.
Example 3
values = [0,0,0]return = 0The sum is already the single digit 0.
Constraints
1 <= values.length <= 10^3.0 <= values[i] <= 9.