reduce = function (a, f, base) { var result = base; each (a, (e) => {result = f(e, result)}); return result; } mul = (x, y) => x * y; reduce([1,2,3,4], mul, 1);
Output