Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: js capitalize first letter 
Javascript :: how to avoid json decode problem in python 
Javascript :: how to find length of a assocative array vuejs 
Javascript :: jqiery check if scroll to end 
Javascript :: javascript sort by date descending 
Javascript :: simple javascript code 
Javascript :: javascript onclick select coordinates 
Javascript :: npm shrinkwrap primordials 
Javascript :: nodejs get param cli 
Javascript :: javascript calculate time 
Javascript :: eslint ignorel ine 
Javascript :: google maps autocomplete js events 
Javascript :: event loop 
Javascript :: 0.1+0.2 javascript 
Javascript :: js get sum by key 
Javascript :: sequelize findone 
Javascript :: union of two arrays javascript 
Javascript :: how to get which key is pressed in javascript 
Javascript :: get random item from array javascript 
Javascript :: converting a string into a number in javascript 
Javascript :: how to select div js 
Javascript :: javascript element edit text 
Javascript :: moment time format by country 
Javascript :: map javascript index 
Javascript :: angular stoppropagatio 
Javascript :: open bootstrap modal with javascript 
Javascript :: react forms 
Javascript :: location of release apk in react native 
Javascript :: react.fragment react native 
Javascript :: binary search algorithm in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =