===== 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.events = new Map();
  }

  subscribe(eventName, callback) {
    if (!this.events.has(eventName)) {
      this.events.set(eventName, []);
    }

    const subscriber = { callback, active: true };
    this.events.get(eventName).push(subscriber);

    return {
      unsubscribe: () => {
        if (!subscriber.active) return;

        subscriber.active = false;
        const subscribers = this.events.get(eventName);
        if (!subscribers) return;

        const index = subscribers.indexOf(subscriber);
        if (index !== -1) {
          subscribers.splice(index, 1);
        }

        if (subscribers.length === 0) {
          this.events.delete(eventName);
        }
      }
    };
  }

  emit(eventName, args = []) {
    const subscribers = this.events.get(eventName);
    if (!subscribers) return [];

    return [...subscribers]
      .filter(subscriber => subscriber.active)
      .map(subscriber => subscriber.callback(...args));
  }
}

module.exports = { EventEmitter };
```