'Making our own stack' (JavaScript Recursion, Exercise 16)


#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];
  }
}

The above code works, but wouldn’t take if I declared stack with let.


#2

Please post a link to this exercise. Thanks.


#3

Recursion in Javascript - 16. Making our own stack


#4

As suspected, that is one of the unsupported modules that never made it into the mainstream track. It was published back in around 2012 when ES6 was still in its infancy and not widely supported yet so the course was written in ES5. That is why the SCT does not accept let.