Skip to content

Instantly share code, notes, and snippets.

@kennethkoontz
Last active December 3, 2021 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennethkoontz/565346215dc60c886fe838377410b15b to your computer and use it in GitHub Desktop.
Save kennethkoontz/565346215dc60c886fe838377410b15b to your computer and use it in GitHub Desktop.
// Cache a function's results by storing them. You may assume
// that the function only takes primitives as arguments.
//
// The function should return a function that, when called, will check if it has
// already computed the result and return that value instead if possible.
//
// Example:
// cacheAdd = myFunction(add);
// add(1,2) = 3
// cacheAdd(1,2) = 3 --> executes add function
// cacheAdd(1,2) = 3 --> returns from cache
// cacheAdd(2,2) = 4--> executes add function
function cacher() {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment