let count = 0;
function add(num){
if(num >= 100){
return count;
}else{
count++;
add(num*3)
}
return count;
}
let ADD = add;
console.log(ADD(1.2));
这是我目前写的,有尝试过把count声明放进add里面去,用闭包去写,但是我写的闭包的形式的返回值是undefined,还有为什么要两次抛出count才行,如果只是判断通过的那一次抛出count的话,返回值是undefined
想请教一下,如果把声明count放进add里面去,该怎么操作
用while或者递归比较好。