Skip to content

Instantly share code, notes, and snippets.

@atiq1589
Created January 28, 2018 06:33
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 atiq1589/370c04d64da01286c249ffb0a80d4729 to your computer and use it in GitHub Desktop.
Save atiq1589/370c04d64da01286c249ffb0a80d4729 to your computer and use it in GitHub Desktop.
Memoization Or caching data without global variable in Javascript.
fact = (function(){
var memo = {};
function clousre(n){
console.log(n);
if (n == 0 || n == 1)
return 1;
if (n in memo)
return memo[n];
memo[n] = n * clousre(n - 1);
return memo[n];
}
return clousre;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment