How does the example in Making our own stack the part of Javascript recursion course work?


#1

// Create an empty array called "stack"
var stack = [];
// Here is our recursive function
function power(base, exponent) {
  // Base case 
  if ( exponent === 0 ) {
    return 1;
  }
  // Recursive case
  else {
	stack[exponent - 1] = base * power(base, exponent - 1);
    return stack[exponent - 1];
  }
}
console.log(power(3,3));

#2

This might be the wrong javascript section or something? Quizzes?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.