1

I'm a noob programmer trying to make a Javascript library, and I had this thought. In Javascript, there is a min and max function, which can use an infinite number of arguments, like Math.min(9, 8, 3, 4), etc. where you can use as many events in that function as you want, so you can take the minimum of an infinite amount of numbers. Is there any way you can implement something like this in a regular function, like the following below?

function test(x, y, z...) {
return Math.min(x, y, z...)
}

Again, sorry if this question is very poorly worded, but I hope someone can understand and help me on this!

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • 2
    `const f = (...args) => void console.log(args);` or the older way with `arguments`. See [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). – ASDFGerte Feb 24 '21 at 00:41
  • not events, they're arguments – SuperStormer Feb 24 '21 at 00:43
  • They are not events. https://developer.mozilla.org/en-US/docs/Glossary/Argument – epascarello Feb 24 '21 at 00:43
  • 3
    Does this answer your question? [Is it possible to send a variable number of arguments to a JavaScript function?](https://stackoverflow.com/questions/1959040/is-it-possible-to-send-a-variable-number-of-arguments-to-a-javascript-function) – SuperStormer Feb 24 '21 at 00:44
  • 1
    That's the opposite, spreading parameters, but there almost certainly is a dupe target for this. – ASDFGerte Feb 24 '21 at 00:45

0 Answers0