const curry = (fn, ...args) => fn.length > args.length ? (...args2) => curry(fn, ...args, ...args2) : fn(...args)
function add(a,b,c,d){
return a + b + c + d
}
const curryAdd = curry(add)
console.log(curryAdd(1,2,3,4))
console.log(curryAdd(1)(2,3,4))
console.log(curryAdd(1,2)(3,4))
console.log(curryAdd(1,2,3)(4))
console.log(curryAdd(1)(2,3)(4))
console.log(curryAdd(1)(2)(3)(4))
const flow = (...fns) => {
return function(...value){
return fns.reduce((result, fn, index) => {
if(index === 0){
return fn(...result)
}
else{
return fn(result)
}
}, value)
}
}
function plus(a,b,c,d){
return a + b + c + d
}
function square(n){
return n * n
}
const plusAndSquare = flow(plus, square, square)
console.log(plusAndSquare(1,2,3,4))