I was trying to solve a problem with recursion .The problem was like this
The multiplicative persistence of an integer, n, is the number of times you have to replace n with the product of its digits until n becomes a single digit integer.
So my code was like this
function multiplicativePersistence(n) {
if(n.toString().length==1) return 0
let c=1
function ismul(num) {
console.log(num,c)
if(num.length==1) return c
let n=num.toString()
let mul=1
for(let i=0;i<n.length;i++) {
mul=mul*parseInt(n[i])
}
if(mul.toString().length!=1) {
c++
return ismul(mul)
}
}
return ismul(n)
}
console.log(multiplicativePersistence(6788))
the output i get is as
6788 1
2688 2
768 3
336 4
54 5
20 6
undefined
why i am getting undefined even though my value of c is correctly update i,e 6 and then i am just returning it