Here is the problem. I have to implement make function:
var sum = function (a, b) { return a + b; }
var mult = function (a, b) { return a * b; }
//'make' function goes here
var res = make(1)(2)(3)(4);
console.log(res(sum)); //OUTPUT: 10
console.log(res(mult)); //OUTPUT: 24
I have implemented it, but I feel like a little better way still exists. :)
So, here is my solution:
function make(a, arr) {
if (a instanceof Function) { return arr.reduce(a); }
arr = arr || [];
arr.push(a);
return function (b) { return make(b, arr); };
}
make(1)(sum)? Considervar comp = (f,g) => x => f(g(x));andvar res = make(x => x *2)(x => x + 1)thenres(comp)(3). The expected output is8but it is impossible with your sugary, sweet function. Attempting to implement this is a fool's errand.