Answers for "currying javascript sum"

0

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
Posted by: Guest on March-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language