Using your language of choice, write a function that takes a variable number of arguments and returns the number of arguments it was called with.
- Your language needs to support variadic argument functions: something callable that takes an arbitrary number of arguments and returns a value.
- Parameters must be able to be passed individually. This means that passing an array would only count for one parameter. You can use an "all passed arguments" array if your language supports it; the restriction is on how the function is called.
- Code that calls this function must not be required to pass the number of arguments in its source. If a compiler inserts the number of arguments as part of a calling convention, that is allowed.
- The arguments can be of any type you want. You can support only a single type (e.g. only supporting
intis still valid), arbitrary types (any type of argument is allowed), or any combination of argument types (e.g. first arg is
int, rest are strings).
- Your function may have a maximum number of arguments (especially since resources are finite), but must support at least 2 arguments.
f([1, 2, 3])returns
1as it is passed an array, not 3 arguments
As this is code-golf, the winning solution is the one that uses the fewest number of bytes.