js


    function compose(f, g, h) {
        return function (x) {return f(g(h(x))) }
    }
    function f(x) {return 'f' + x; }
    function g(x) { return 'g' + x; }
    function h(x) { return 'h' + x; }    alert(f(g(h('1'))))
    alert(compose(f,g,h)(1))
好像有点换汤没换药

解决方案 »

  1.   

    换个药吧。。    function compose() { var func = Array.prototype.slice.call(arguments); return function (x) { while (fn = func.pop()) x = fn(x); return x; } }
      

  2.   


            const [f,g,h]=[
                x=>`f${x}`,
                x=>`g${x}`,
                x=>`h${x}`
            ]
            function compos(...funcs){
                return x=>funcs.reduce((a,b)=>b(a),x)
            }
            const r=compos(f,g,h)('com');
            console.log(r);