Created
December 11, 2013 02:03
-
-
Save w495/7903994 to your computer and use it in GitHub Desktop.
add(1)(2)(3) // 6
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
'use strict'; // Luke | |
// ------------------------------------------------- | |
// Просто | |
// ------------------------------------------------- | |
var add = function(x) { | |
var temp = x; | |
var f = function (y) { | |
temp += y; | |
return f; | |
}; | |
f.valueOf = function () { return temp; }; | |
return f; | |
} | |
// ------------------------------------------------- | |
// Сложно | |
// ------------------------------------------------- | |
Function.prototype.curry = function() { | |
if (!arguments.length) | |
return this; | |
var fn = this; | |
var cached = arguments[0]; | |
return function() { | |
return fn.apply( | |
this, | |
[cached].concat([arguments[0]]) | |
); | |
} | |
}; | |
var addc = function(x) { | |
return (function (x, y) { return x + y }).curry(x) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment