Skip to content

Instantly share code, notes, and snippets.

@daifu
Created December 18, 2012 23:11
Show Gist options
  • Select an option

  • Save daifu/4332977 to your computer and use it in GitHub Desktop.

Select an option

Save daifu/4332977 to your computer and use it in GitHub Desktop.
var cached = {};
function factorial(num) {
if (num === 1)
return 1;
else if (cached[num] !== undefined) {
return cached[num];
}
else {
return num * factorial(num - 1);
}
}
var start = new Date().getMilliseconds();
factorial(19000);
var end = new Date().getMilliseconds();
console.log(end - start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment