Loading...
intermediate
Problem 06 • Step 07
power
Exponentiation: base raised to the exp power.
power(base)(0)= 1power(base)(exp)=base*power(base)(exp - 1)
This combines two ideas you’ve already used separately:
- Currying from
max— the function takesbasefirst andexpsecond, through nested lambdas - Recursion from
sum-to— the inner function calls itself with a smaller exponent until it reaches the base case
The new challenge is the recursive call. In sum-to, the recursive call was straightforward: ["sum-to", ["n", "-", 1]]. But power is curried — you need to call it with base first to get a function, then call that function with exp - 1. Two applications, not one.
Look at how the tests call power: [["power", 2], 8]. The recursive call inside the body has the same shape, but with variable names instead of literal numbers.