Skip to content

Instantly share code, notes, and snippets.

@agar3s
Created December 6, 2014 19:31
Show Gist options
  • Save agar3s/21ef60d0867d19797352 to your computer and use it in GitHub Desktop.
Save agar3s/21ef60d0867d19797352 to your computer and use it in GitHub Desktop.
var memo = {
'0': 0,
'1': 1,
'2': 2,
'3': 6
};
function main(n){
if(n<=2){
return memo[n];
}
var n1 = memo[n-1] || main(n-1);
memo[n] = n*n1;
return memo[n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment