Generate the reduceable function.
npm install @jswork/reduce-fns
import reduceFns from '@jswork/reduce-fns';
const sum = (a, b) => a + b;
const mul = (a, b) => a * b;
const sumAll = reduceFns(
() => 0,
(args) => args[0],
sum
);
const mulAll = reduceFns(
() => 1,
(args) => args[0],
mul
);
console.log(sumAll(1, 2, 3)) // 6
console.log(mulAll(1, 2, 3, 4, 5)) // 120
Code released under the MIT license.