Skip to content

Instantly share code, notes, and snippets.

@apolopena
Created January 10, 2019 07:18
Show Gist options
  • Save apolopena/a22c78a3dbc0bdccbcb455b77c6b8158 to your computer and use it in GitHub Desktop.
Save apolopena/a22c78a3dbc0bdccbcb455b77c6b8158 to your computer and use it in GitHub Desktop.
Javascript Currying Example
// currying example
var add = function(vala){
return function(valb){
return vala + valb;
}
}
console.log(add(2)(2)); // outputs 4
// or more currying just not chained which is the same thing
var twoplus = add(2);
console.log(twoplus(2)); // outputs 4
@apolopena
Copy link
Author

apolopena commented Jan 10, 2019

ES5 oneliner
var a=function(b){return function(c){return b+c;}};console.log(a(4)(4));//outputs 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment