curry MST

按要求实现curry函数

const addFn = (...args) => args.reduce((total, cur) => total + cur, 0)
const curry = (fn) => {
    let params = []
    return function f(...rest) {
        if (rest.length) {
            params.push(...rest)
            return f
        }
        return fn(...params)
    }
}
const add = curry(addFn)
const value = add(1, 2)(3)(4)()
console.log(value) // 10

  

posted @ 2023-02-14 13:25  671_MrSix  阅读(11)  评论(0编辑  收藏  举报