I'm encountering some difficulty with a specific challenge and could use some clarification. Thank you in advance. The task involves finding the sum of numbers within an array, such as:
16 --> 1 + 6 = 7
942 --> 9 + 4 + 2 = 15
15 --> 1 + 5 = 6
....and so on.
My current code only works for finding the sum of two numbers.
function digital_root(n) {
const arrayOfDigits = Array.from(String(n), Number);
let sum = arrayOfDigits.reduce(function (memo, val) {
return memo + val;
});
return sum;
}