I just started out with recursion so I was solving a question which is like
Create a function that takes numbers as arguments, adds them together, and returns the product of digits until the answer is only 1 digit long.
sumDigProd(16, 28) ➞ 6
// 16 + 28 = 44
// 4 * 4 = 16
// 1 * 6 = 6
sumDigProd(0) ➞ 0
sumDigProd(1, 2, 3, 4, 5, 6) ➞ 2
so i did it with recursion as
function sumDigProd(...digits) {
let ans = digits.reduce((a, b) => a + b, 0);
console.log(ans);
const result=calc(ans);
function calc(ans) {
ans = ans.toString();
let pro = 1;
for (let i = 0; i < ans.length; i++) {
pro = pro * ans[i];
}
console.log(pro);
while (pro > 10) {
calc(pro);
}
return pro
}
return result
}
console.log(sumDigProd(16,28));
so I am running it in infinite loop
sevenBoom()?pro.