currying function to add sum in javascript code example
Example: currying javascript sum
// 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