SOURCE

// 设计一个柯里化函数(currying ),实现sum(100,200)(300)();得到600

// function sum(...args) {
//     let concatArgs = []
//     function fn2(...args2) {
//         concatArgs = [...concatArgs, ...args2]
//         return fn2
//     }
//     fn2.toString = () => {
//         return concatArgs.reduce((a, b) => a + b, 0)
//     }
//     return fn2(...args)
// }

// let a = sum(100, 200)(300)()

// console.log(a)




function sum(...args) {
    let argsList = []

    const currying = (...args2) => {
        argsList = [...argsList, ...args2]
        return currying
    }

    currying.toString = () => {
        return argsList.reduce((a, b) => a + b, 0)
    }

    return currying(...args)
}

const result = sum(100, 200)(300)()

console.log(result)
console 命令行工具 X clear

                    
>
console