Skip to content

Instantly share code, notes, and snippets.

@pid
Forked from jorinvo/factorialWithLambdaCalc.js
Last active August 29, 2015 14:15
Show Gist options
  • Save pid/a2ba9362f3c72f1112ad to your computer and use it in GitHub Desktop.
Save pid/a2ba9362f3c72f1112ad to your computer and use it in GitHub Desktop.

Revisions

  1. jorin revised this gist Feb 16, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions factorialWithLambdaCalc.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // Y Combinator
    // makes the recursion
    (function(improver) {
    return (function(gen) { return gen(gen) })(
    function(gen) {
    @@ -7,9 +9,11 @@
    }
    )
    })(
    // this part is the condition for the factorial
    function(partial) {
    return function(n) {
    return n === 0 ? 1 : n * partial(n - 1)
    }
    }
    // pass any number here to get its factorial
    )(5)
  2. jorin created this gist Feb 16, 2015.
    15 changes: 15 additions & 0 deletions factorialWithLambdaCalc.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    (function(improver) {
    return (function(gen) { return gen(gen) })(
    function(gen) {
    return improver(function(v) {
    return gen(gen)(v)
    })
    }
    )
    })(
    function(partial) {
    return function(n) {
    return n === 0 ? 1 : n * partial(n - 1)
    }
    }
    )(5)