If you use a library like Lodash, you can use _.zipWith, which iterates several arrays at once all in parallel, calling the provided function with the elements of the arrays.
const results = _.zipWith(funcs, args, (f, a) => f(a));
If you want a simple implementation of zipWith without importing the library, use:
const zipWith = (...arrays) => {
const func = arrays.pop();
return arrays[0].map((_, i) => func(...arrays.map(arr => arr[i])));
};
const zipWith = (...arrays) => {
const func = arrays.pop();
return arrays[0].map((_, i) => func(...arrays.map(arr => arr[i])));
};
const funcs = [
a => a * 2,
a => a * 3,
a => a * 4,
a => a * 5
];
const args = [1, 2, 3, 4];
console.log(zipWith(funcs, args, (f, a) => f(a)));