Files
30-seconds-of-code/snippets/js/s/invoke-functions-on-arguments.md
Angelos Chalaris 9d032ce05e Rename js snippets
2023-05-19 20:23:47 +03:00

557 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Invoke functions on arguments snippet javascript
function
armchair-in-yellow 2020-10-21T21:54:53+03:00

Creates a function that invokes each provided function with the arguments it receives and returns the results.

  • Use Array.prototype.map() and Function.prototype.apply() to apply each function to the given arguments.
const over = (...fns) => (...args) => fns.map(fn => fn.apply(null, args));
const minMax = over(Math.min, Math.max);
minMax(1, 2, 3, 4, 5); // [1, 5]