📜  currying javascript sum - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:27.240000             🧑  作者: Mango

代码示例1
// Curring Adding two items
const sum = x => y => x + y
sum(2)(2)//4
// Adding three or more items
const sum = x => (y=0) => (...z) => +x + +y + +z.reduce((prev,curr)=>prev+curr,0)
sum(2)()()//2
sum(2)(2)()//4
sum(2)(2)(2)//6
sum(2)(2)(2)(2)//8