Cache a Function's Results, Keeping Its Types

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

The problem

  • medium
  • Code

Write memoize(fn): return a function that calls fn once per distinct list of arguments (compare them by JSON.stringify of the arguments) and returns the cached result after that. The returned function must keep fn's exact parameter and return types, so callers lose nothing.

Your code must pass

  • Calls fn once per distinct arguments
  • Returns the cached result
  • Has no type errors
  • Keeps fn's parameter types
  • Keeps fn's return type