How can a single apply(criteria, n) answer completely different questions just by swapping which function you hand it?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Write a function call_on(f, x) that returns the result of calling the function f on the value x.
Hint: a parameter that holds a function can be called just like any other function.
A function-valued parameter called as f(z)
Trace func_a(), func_b(2) and func_c(func_b, 3), recording the console lines, the 7 that print(5 + func_b(2)) produces, and the 3 that func_c hands back through f(z).
Writing apply(criteria, n)
Write the body count = 0, for i in range(n + 1), if criteria(i): count += 1, return count, and record range(n + 1) as the form that includes n itself.
Swapping the criteria function
Record apply(is_even, 10) giving 6 with the matches 0, 2, 4, 6, 8 and 10, and apply(is_five, 10) giving 1 with the single match 5, over identical apply code.