Skip to content

Instantly share code, notes, and snippets.

@eduardomoroni
Created April 6, 2018 11:18
Show Gist options
  • Save eduardomoroni/3ca1f89863c8d2bb7b255f866ac1faee to your computer and use it in GitHub Desktop.
Save eduardomoroni/3ca1f89863c8d2bb7b255f866ac1faee to your computer and use it in GitHub Desktop.
JS Memoize function
function memoize(fn) {
var cachedArg;
var cachedResult;
return function(arg) {
if (cachedArg === arg) {
return cachedResult;
}
cachedArg = arg;
cachedResult = fn(arg);
return cachedResult;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment