Run After N Calls

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write after(n, fn), where n is a whole number of at least 1: return a function whose first n minus 1 calls do nothing and return undefined. From the nth call on, every call calls fn with its own arguments and returns fn's result. So after(1, fn) calls fn straight away, and after(3, fn) waits for the third call.

Your code must pass

  • Doesn't call fn before the nth call
  • Calls fn on the nth call and every call after it
  • Passes the arguments on and returns fn's result
  • With n of 1, calls fn straight away