How can I sum divided into an array digits of a specified number to one whole, e.g. 28 => 2 + 8 => 1?
const addDigits = (num) => {
let str = num.toString();
let sum = str.split('');
for (let i = 0; i < str.length; i += 1) {
sum = parseInt(str.charAt(0) + str.charAt(i));
}
return sum;
}