Array.prototype.map()
and Function.prototype.apply()
to apply each function to the given arguments....
) to call converger
with the results of all other functions.const converge = (converger, fns) => (...args) =>
converger(...fns.map(fn => fn.apply(null, args)));
const average = converge((a, b) => a / b, [ arr => arr.reduce((a, v) => a + v, 0), arr => arr.length ]); average([1, 2, 3, 4, 5, 6, 7]); // 4
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️