Created
May 20, 2016 21:07
-
-
Save daronwolff/e9877b694bf56688b3e96567e7a7fe81 to your computer and use it in GitHub Desktop.
Write a function that takes a function and an argument, and returns a function that can supply a second argument add3 = curry(add,3); add3(4); // 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var add = (function(a) { | |
return function(b) { | |
return a + b; | |
} | |
}); | |
var mul = (function(a) { | |
return function(b) { | |
var total = a * b; | |
return total; | |
} | |
}); | |
function curry(f, x) { | |
return f(x) | |
} | |
add3 = curry(add, 3); | |
console.log(add3(4)); // 7 | |
var a = curry(add, 3)(3); // 6 | |
var b = curry(mul, 5)(6); // 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment