函数柯理化

const curring = fn => {

    const { length } = fn

    const curried = (...args) => {

        return (args.length >= length

              ? fn(...args)

              : (...args2) => curried(...args.concat(args2)))

    }

    return curried

}

const listMerge = (a, b, c) => [a, b, c]

const curried = curring(listMerge)

console.log(curried(1)(2)(3)) // [1, 2, 3]

console.log(curried(1, 2)(3)) // [1, 2, 3]

console.log(curried(1, 2, 3)) // [1, 2, 3]

你可能感兴趣的:(函数柯理化)