garrettmac
9/15/2017 - 4:22 AM

MEDIUM BLOG POST - Javascript’s 3 Major Paradigms: The Five tenets of Functional Programming [part 3 of 4]

MEDIUM BLOG POST - Javascript’s 3 Major Paradigms: The Five tenets of Functional Programming [part 3 of 4]

function add(a, b) { 
	return a + b; 
}
add(3, 4);//returns 7
//This is a function that takes two arguments, a and b, and returns their sum. We will now curry this function:

function add(a) { 
	return function (b) { 
		return a + b; 
	} 
}

//This is a function that takes one argument, a, and returns a function that takes another argument, b, and that function returns their sum.
add(3)(4);
var add3 = add(3);
add3(4);