Skip to content

Instantly share code, notes, and snippets.

@dvitiuk-opensource
Last active August 29, 2015 14:15
Show Gist options
  • Save dvitiuk-opensource/61f4c36afb94c02cf020 to your computer and use it in GitHub Desktop.
Save dvitiuk-opensource/61f4c36afb94c02cf020 to your computer and use it in GitHub Desktop.
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