柯里化函数

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]

  

原文地址:https://www.cnblogs.com/LeoXnote/p/14154901.html