Last active
August 29, 2015 14:15
-
-
Save dvitiuk-opensource/61f4c36afb94c02cf020 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 add(x, y) { | |
return x + y; | |
} | |
function mul(x, y) { | |
return x * y; | |
} | |
function make(){ | |
//'use strict'; | |
var argument = arguments[0]; | |
this.savedValues = this.savedValues || []; | |
if(typeof argument === 'function'){ | |
// Возвращаем результат | |
return this.savedValues.reduce(argument); | |
} else { | |
this.savedValues.push(argument); | |
return make.bind(this); | |
} | |
} | |
var s = make(1)(2)(3)(4)(5); | |
console.assert(s(add) == 15); | |
console.assert(s(mul) == 120); | |
s(10)(7)(0); | |
console.assert(s(add) == 32); | |
console.assert(s(mul) == 0); | |
var x = make(5)(10)(15); | |
console.assert(x(add) == 30); | |
console.assert(x(mul) == 750); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment