Last active
October 22, 2015 07:32
-
-
Save meowtec/145f3246fde7f2df1a23 to your computer and use it in GitHub Desktop.
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
function currying(fun) { | |
function curryingIter(fun, len) { | |
if (len < 2) { | |
return fun | |
} | |
return curryingIter(function() { | |
var args = [].slice.call(arguments) | |
return function(x) { | |
args.push(x) | |
return fun.apply(null, args) | |
} | |
}, len - 1) | |
} | |
return curryingIter(fun, fun.length) | |
} | |
// use | |
function add(x, y, z) { | |
return x + y + z | |
} | |
var newAdd = currying(add) | |
newAdd(2)(3)(4) // 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment