Skip to content

Instantly share code, notes, and snippets.

@smithcommajoseph
Created September 18, 2013 19:19
Show Gist options
  • Save smithcommajoseph/6614158 to your computer and use it in GitHub Desktop.
Save smithcommajoseph/6614158 to your computer and use it in GitHub Desktop.
if (typeof Math.factorial === "undefined") {
Math.factorial = function factorial (n) {
if (n == 0 || n == 1)
return 1;
if (Math.factorial.f[n] > 0)
return Math.factorial.f[n];
else
return Math.factorial.f[n] = factorial(n-1) * n;
};
Math.factorial.f = [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment