I m trying to solve the Recursive Digit sum of Hackerrank. I think I am done but getting undefined at the end of return of recursive function
function superDigit(n, k) {
// Write your code here
let str = "";
for (let i = 0; i < k; i++) {
str = str + n;
}
if (Math.floor(parseInt(str) / 10) === 0) {
return n;
} else {
let t=calculateSum(str.split(''));
console.log('done:',t)
return t
}
function calculateSum(value) {
let arr = value;
let sum = 0;
console.log(arr);
for (let i = 0; i < arr.length; i++) {
sum = sum + parseInt(arr[i]);
}
if (Math.floor(sum / 10) === 0) {
console.log(sum);
return sum;
} else {
calculateSum(sum.toString().split(''));
}
}
}
console.log("tttt:"+superDigit(9, 3));