Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
 
PREVIOUS NEXT
Tagged: #currying #javascript #sum
ADD COMMENT
Topic
Name
3+1 =