Answer the question
In order to leave comments, you need to log in
Recursive multiplication of digits of an integer, how to find out the number of function calls?
Hello.
The program should implement bitwise multiplication of a positive integer until 1 bit remains and return the number of steps to this result. Example:
99999=>59049=>0===2 steps // 9*9*9*9*9=>5*9*0*4*9=>0;
13=>3===1 step // 1*3=>3;
999=>729=>126=>12=>2===4 steps // 9*9*9=>7*2*9=>1*2*6=>1*2=>2;
7=>7===0 steps //
Is it possible to insert a function call counter into the recursion?
let steps = 0;
function umnozhenie(x) {
steps += 1;
x = String(x).match(/[0-9]/g).map(Number).reduce((a, b) => a * b);
if (x >= 10) { x = umnozhenie(x); };
return steps;
}
return
I put the function itself in, then I get the correct value of the final digit. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question