Created
August 28, 2016 04:27
-
-
Save gasolin/80c4a43b40ba80a0482e64efb2fe1b41 to your computer and use it in GitHub Desktop.
memorize.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://jigsawye.gitbooks.io/mostly-adequate-guide/content/ch3.html | |
var memorize = function(f) { | |
var cache = {}; | |
return function() { | |
var arg_str = JSON.stringify(arguments); | |
cache[arg_str] = cache[arg_str] || f.apply(f, arguments) | |
return cache[arg_str]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment