https://github.com/mozilla/gecko-dev
Raw File
Tip revision: eb17cca53e5f453724c0a8ca5a12d7971e2b4442 authored by ffxbld on 16 May 2012, 00:43:38 UTC
Added FENNEC_13_0b2_RELEASE FENNEC_13_0b2_BUILD3 tag(s) for changeset 88ee14110a74. DONTBUILD CLOSED TREE a=release
Tip revision: eb17cca
Y.js
// The Y combinator, applied to the factorial function

function factorial(proc) {
    return function (n) {
        return (n <= 1) ? 1 : n * proc(n-1);
    }
}

function Y(outer) {
    function inner(proc) {
        function apply(arg) {
            return proc(proc)(arg);
        }
        return outer(apply);
    }
    return inner(inner);
}

print("5! is " + Y(factorial)(5));
back to top