Implement a function argumentStats(fn) that wraps a function fn and returns a new function.
The wrapped function should:
Additionally, the wrapped function should provide two methods:
.totalCalls(): returns the total number of times the function has been called..totalArgs(): returns the total number of arguments (after flattening) across all calls.Example
function sum(a, b) { return a + b; } const wrappedSum = argumentStats(sum); wrappedSum(1, 2); // 3 wrappedSum([3, 4], 5); // 12 wrappedSum.totalCalls(); // 2 wrappedSum.totalArgs(); // 5 (1,2,3,4,5)
Hints
(...args) to capture arguments.JavaScript Function
No test results yet
Click "Run" to execute tests