Created
September 27, 2013 07:13
-
-
Save kiddkai/6725125 to your computer and use it in GitHub Desktop.
Revisions
-
kiddkai created this gist
Sep 27, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ /** * curry * * var curried = curry(function(a, b, c) { * console.log(a+b+c); * }); * * * curried(2)(2)(2); // => 6 * curried(2,2)(2); // => 6 * curried(2,2,2); // => 6 * */ function curry(fn) { var totalArgsLength = fn.length; var params = []; function genCurried() { var args = [].slice.call(arguments); params = params.concat(args); if (params.length < totalArgsLength) { return genCurried; } else { return fn.apply(this, params); } } return genCurried; }