Skip to content

Instantly share code, notes, and snippets.

@tkheyfets
Created March 18, 2016 14:26
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 tkheyfets/f0e4d6c3c32a8ff1cdef to your computer and use it in GitHub Desktop.
Save tkheyfets/f0e4d6c3c32a8ff1cdef to your computer and use it in GitHub Desktop.
function memoize(fn) {
var slice = Array.prototype.slice,
cache = [];
return function () {
var args = slice.call(arguments),
result = cache[args];
if (!result) {
result = cache[args] = fn.apply(this, args);
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment