===== ISTEM =====
Solve the following programming task.

TASK: Event Emitter

Write an 'EventEmitter' class with 'subscribe(eventName, callback)' and 'emit(eventName, args)' methods. The 'subscribe' method must return { unsubscribe: () => void }.

STARTER CODE (javascript):
class EventEmitter {
  // Write your code here
}

module.exports = { EventEmitter };


RULES:
- Keep the function name and signature EXACTLY as given.
- Return working code only. No explanations.
- Put the code in a single ``` block.
- Try to solve it first. If you genuinely cannot, write only this single
  line instead of producing faulty code: CANNOT_SOLVE

===== HAM YANIT =====
```javascript
class EventEmitter {
  constructor() {
    this.listeners = new Map();
  }

  subscribe(eventName, callback) {
    if (!this.listeners.has(eventName)) {
      this.listeners.set(eventName, []);
    }
    const arr = this.listeners.get(eventName);
    arr.push(callback);
    return {
      unsubscribe: () => {
        const list = this.listeners.get(eventName);
        if (!list) return;
        const idx = list.indexOf(callback);
        if (idx !== -1) {
          list.splice(idx, 1);
        }
        if (list.length === 0) {
          this.listeners.delete(eventName);
        }
      },
    };
  }

  emit(eventName, args) {
    const list = this.listeners.get(eventName);
    if (!list) return;
    // Use a shallow copy to avoid issues if the list is modified during iteration
    for (const cb of list.slice()) {
      if (Array.isArray(args)) {
        cb(...args);
      } else {
        cb(args);
      }
    }
  }
}

module.exports = { EventEmitter };
```