Please help me understand this recursive function…
var stack = Array;
function power(base, exponent){
if ( exponent === 0 ) {
return 1;
} else {
stack[exponent-1] = base * power(base, exponent - 1);
return stack[exponent-1];
}
}
I dont understand what
stack[exponent-1]
is doing
I did console log of stack[exponent-1] using
O/P:
So function class recursively until exponent become 0 (nth call), then it will start returning results