Run a Function Only Once

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

The problem

  • easy
  • Code

Write once(fn): return a new function that calls fn the first time it's called, with the arguments it was given, and returns fn's result. Every later call returns that same first result without calling fn again, even if the result was undefined.

Your code must pass

  • Calls fn on the first call and returns its result
  • Never calls fn a second time
  • Later calls return the first result
  • Remembers a first result of undefined