SOURCE

let filters = [
    function(ctx, next){
        if (ctx.amount < 5){
            console.log('passed 1')
            return
        }
        next(ctx)
    },
    function(ctx, next){
        if (ctx.amount < 10){
            console.log('passed 2')
            return
        }
        next(ctx)
    },
    function(ctx, next){
        if (ctx.amount < 50){
            console.log('passed')
            return
        }
        next(ctx)
    },
    function(ctx, next){
        console.log('fail')
    }
]
;
function reverseReduce(arr, func){
    let last = arr[arr.length - 1]
    for(let i = arr.length - 2; i >= 0 ; i-- ){
        last = func(last, arr[i])
    }
    return last
}
let filterChain = reverseReduce(filters, (b, a) =>{
    return function(ctx){
        a(ctx, b)
    }
});

filterChain({amount: 51})
console 命令行工具 X clear

                    
>
console