Implement Spy Decorator

The Decorator is a design pattern that allows you to modify the existing functionality of a function by wrapping it in another function.

In the JavaScript testing framework Jest, a "spy" is typically used to monitor the behavior of a function:

spyOn(object, methodName);

You are required to implement Spy Decorator, which counts how many times the given function was called and with which arguments.

Example

const obj = {
  counter: 1,
  add(num) {
    this.counter += num;
  },
};

const spy = spyOn(obj, "add");

obj.add(1); // 2
obj.add(2); // 4

console.log(obj.counter); // 4
console.log(spy.calls); // [ [1], [2] ]