function sum(...args) {
return args.reduce((acc, val) => acc + val);
}
function mul(...args) {
return args.reduce((acc, val) => acc * val);
}
function applyAll(func, ...values) {
return func(...values);
}
alert( applyAll(sum, 1, 2, 3) ); // 6
alert( applyAll(mul, 2, 3, 4) ); // 24
alert( applyAll(Math.max, 2, -2, 3) ); // 3
alert( applyAll(Math.min, 2, -2, 3) ); // -2
Find more questions by tags JavaScript
In other words, this task uses only the ability the apply method to deploy the array of arguments in the argument list for the invoked function. - oleta.Wi commented on June 8th 19 at 17:40