Skip to content

Instantly share code, notes, and snippets.

@ikr
Created December 4, 2010 16:34
Show Gist options
  • Save ikr/728304 to your computer and use it in GitHub Desktop.
Save ikr/728304 to your computer and use it in GitHub Desktop.
Factorial in JS without loops or direct recursion
var ikr = {
partFactorial: function (self) {
return (function (n) {
return (
(0 === n)? 1 : (n * (self(self))(n - 1))
);
});
},
factorial: function (n) {
return this.partFactorial(this.partFactorial)(n);
},
show: function () {
alert(this.factorial(5));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment