Created
November 8, 2012 05:55
-
-
Save shuhrat/4037080 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
var s = make(1)(2)(3)(4)(5); | |
var add = function (a, b) { return a + b; }; | |
var mul = function (a, b) { return a * b; }; | |
s(add); //15 | |
s(mul); // 120 | |
//Write make =) |
var make = (function() {
var cache = [],
cacheHandler,
result, max;
cacheHandler = function(value) {
if (typeof value === 'function') {
result = null;
max = cache.length;
if (max >= 2) {
result = cache[--max];
while(max--) {
result = value(result, cache[max]);
}
}
return result;
} else {
cache.push(value);
return cacheHandler;
}
}
return cacheHandler;
}());
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
так лучшее будет