https://github.com/mozilla/gecko-dev
Raw File
Tip revision: 0cdf426b06ee6e7dbde78fd5dd9be8e6012ed406 authored by Ed Morley on 11 January 2013, 22:20:21 UTC
Bug 782633 - Make the "missing output line for total leaks!" failure mode a warning rather than TEST-UNEXPECTED-FAIL; r=ted a=test-only
Tip revision: 0cdf426
Y.js
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// 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