Created
December 15, 2015 22:15
-
-
Save lovasoa/9f34fd270cac31ee8bb3 to your computer and use it in GitHub Desktop.
Memoization implementation in javascript
This file contains hidden or 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
function memoize(f) { | |
var dict = {}; | |
return function() { | |
var args = JSON.stringify(arguments); | |
if(dict.hasOwnProperty(args)) return dict[args]; | |
var res = f.apply(null, arguments); | |
dict[args] = res; | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment