compose function
JavaScript
function compose(f1, f2) {
return function(el) {
return f2(f1(el));
}
}
function sum(val, i) {
//return function(i) {
return val + i;
//}
}
function mul(val, i) {
//return function(i) {
return val * i;
//}
}
var composed = compose(sum.bind(null, 2), mul.bind(null, 3));
var riba = Array(10).fill(0).map(function(el, i) {
return this.current = composed(this.current);
}, {current: 0})
console.log('riba', riba);