Skip to content

Instantly share code, notes, and snippets.

@collinschaafsma
Last active May 26, 2018 00:14
Show Gist options
  • Save collinschaafsma/3828517e1546ba65c0ed9104abb72625 to your computer and use it in GitHub Desktop.
Save collinschaafsma/3828517e1546ba65c0ed9104abb72625 to your computer and use it in GitHub Desktop.
// cache any function call, use the args as a key
const memoize = (fn) => {
let cache = {};
return (...args) => {
if (cache[args]) {
return cache[args];
} else {
let result = fn.apply(this, args);
cache[args] = result;
return result;
}
}
}
// const fastFn = memoize(slowFn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment