I am currently facing an issue with the following problem:
Your task is to create a function called persistence, which takes a positive parameter num and calculates its multiplicative persistence. Multiplicative persistence refers to the number of times you need to multiply the digits in num until you end up with a single digit.
function persistence(num) {
let count = 0;
let numStr = num.toString();
if (numStr.length === 1){
return 0
}
if (numStr.length === 2){
while (numStr.length > 1){
count += 1
numStr = (Number(numStr[0])*Number(numStr[1])).toString()
}
}
if (numStr.length === 3){
while (numStr.length > 1){
count += 1
numStr = (Number(numStr[0])*Number(numStr[1])*Number(numStr[2])).toString()
}
}
return count
}
persistence(999) //solution 4
I am facing an issue where I keep getting an "Execution Timed Out (12000 ms)" error. While I understand that there are various approaches to solving this problem, I am particularly interested in understanding what might be incorrect with my code.