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.
Specifics:
- 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
int
is still valid), arbitrary types (any type of argument is allowed), or any combination of argument types (e.g. first arg isint
, rest are strings). - Your function may have a maximum number of arguments (especially since resources are finite), but must support at least 2 arguments.
Samples:
f()
returns0
f(1)
orf("a")
returns1
f([1, 2, 3])
returns1
as it is passed an array, not 3 argumentsf(1, 10)
orf(1, "a")
returns2
As this is code-golf, the winning solution is the one that uses the fewest number of bytes.