Last active
January 26, 2016 05:43
-
-
Save mistidoi/f5c90a2497ead818bf4c to your computer and use it in GitHub Desktop.
putting it to use!
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
var memoize; | |
memoize = function(func) { | |
var cache; | |
cache || (cache = {}); | |
return function() { | |
var key; | |
key = JSON.stringify(arguments); | |
if (cache[key]) { | |
return cache[key]; | |
} else { | |
return cache[key] = func.apply(this, arguments); | |
} | |
}; | |
}; | |
add3Numbers = function (a,b,c) { console.log("I just ran!"); return a + b + c; }; | |
add3Numbers(1,2,3); | |
// I just ran! | |
// 5 | |
memoizedAdd3Numbers = memoize(add3Numbers); | |
memoizedAdd3Numbers(3,4,5); | |
// I just ran! | |
// 12 | |
memoizedAdd3Numbers(3,4,5); | |
// 12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment