Return how many arguments a function was called with
An analytics SDK has an overloaded call, track(event) versus track(event, undefined), and the two must behave differently: passing undefined on purpose clears a property, while leaving the argument out keeps it. Checking value === undefined cannot tell these apart, but the number of arguments can.
Implement countArguments. It returns how many arguments it was called with.
countArguments(...anything) // => number
undefined, null, 0, '', NaN, objects, and functions each count as one.countArguments(...list)) passes each element as its own argument. Holes in a spread array are passed as undefined, so they count too.call, apply, or bind (bound arguments count), or as a method of an object.countArguments.length is 0. Use rest parameters or arguments.countArguments(); // => 0
countArguments('signup'); // => 1
countArguments('signup', undefined); // => 2
countArguments(null, 0, '', NaN); // => 4
countArguments([1, 2, 3]); // => 1
countArguments(...[1, 2, 3]); // => 3
countArguments.call(null, 'a', 'b'); // => 2
countArguments.apply(null, ['a', 'b', 'c']); // => 3
countArguments.bind(null, 'a')('b'); // => 2
countArguments.length; // => 0