SOURCE

//设计一个函数,使f(1)=1,f(1,2,3)=6,
//f(1)(2)(3)=6,f(1)(2,3)(4,5)=15
function add(...args){
    let arr = args
    function fn(...newArgs){
        arr = [...arr,...newArgs]
        // console.log(arr)
        return fn
    }
    fn.toString = fn.valueOf = function(){
        return arr.reduce((acc,cur) => acc+=cur )
    }
    return fn
}
console.log(add(1,2,3)(2,3)(3)(1,3))
console 命令行工具 X clear

                    
>
console