Skip to content

Instantly share code, notes, and snippets.

@ikr
Created December 11, 2010 11:12
Show Gist options
  • Save ikr/737318 to your computer and use it in GitHub Desktop.
Save ikr/737318 to your computer and use it in GitHub Desktop.
Factorial function defined for n ∈ [0, 6]
var identity = function (x) {
return x;
};
var almost_factorial = function (f) {
return function (n) {
return (
(0 === n)?
1 :
(n * f(n - 1)));
};
};
var factorial6 =
almost_factorial(
almost_factorial(
almost_factorial(
almost_factorial(
almost_factorial(
almost_factorial(
almost_factorial(identity)))))));
var factorial = almost_factorial(factorial);
var show = function () {
alert(factorial6(6));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment