let output = solution(123);
console.log(output); // 6
let output = solution(987);
console.log(output); // 24
(1) 풀이 1
function solution(num) {
let str = String(num);
let result = 0;
for (let el of str) {
result += el * 1
}
return result;
}
(2) 풀이 2
function solution(num) {
return num.toString().split('')
.reduce((acc, curr) => acc + curr * 1, 0);
}