max
max returns the larger of two numbers. But your functions only take one argument. How do you write a function that needs two?
Look at how the tests call max:
evaluate([["max", 3], 5])
This is two function calls, not one. First, ["max", 3] calls max with 3 and gets back a function. Then that function is called with 5 to get the final result.
You’ve seen this pattern before — the operators work this way. + is a function that takes the left operand and returns a function that takes the right. That’s currying.
Now you’re writing a curried function yourself. The outer lambda takes the first number. It returns an inner lambda that takes the second number. The inner lambda has access to both — because it closes over the outer lambda’s parameter.
The body of the inner lambda is a choice: which number is larger? You’ve already used if and comparisons.