← Back to challenges

Anonymous Functions All the Way Down

JavaScriptHardfunctional_programminghigher_order_functionsrecursion

Instructions

Create a function which takes a parameter n and returns a function such that it, when called n times, returns the string "innokodakademija".

Examples

lambdaDepth(0) ➞ "innokodakademija"

lambdaDepth(1)() ➞ "innokodakademija"

lambdaDepth(2)()() ➞ "innokodakademija"

typeof lambdaDepth(2)() ➞ "function"

Notes

  • num will always be a non-negative integer.
  • If num == 0, return "innokodakademija".
  • If num > 0, return a function.
  • All non-example test cases come in two forms: checking whether lambda_depth(k), after being called k times, returns a string, and checking whether lambda_depth(k) returns a function.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.