Implement an EventEmitter class that supports subscribing to events and emitting them.
Since test cases cannot pass actual callback functions, we use integer IDs to represent callbacks.
The EventEmitter class should support the following operations:
EventEmitter() — Initialize the event emitter.on(event, callbackId) — Register the integer callbackId for the given event name (a string). Multiple IDs can be registered for the same event, and the same ID can be registered multiple times.emit(event) — Trigger the given event. Return an array of all registered callback IDs for that event, in the order they were registered. If the event has no subscribers, return an empty array.off(event, callbackId) — Remove the first occurrence of callbackId from the given event. If the ID is not registered for that event, do nothing.["EventEmitter","on","on","emit","off","emit"]
[[],["click",1],["click",2],["click"],["click",1],["click"]][null,null,null,[1,2],null,[2]]Event names are non-empty strings1 <= callbackId <= 1000At most 1000 calls will be made to on, emit, and offThe same callbackId can be registered multiple times for the same eventRun your code to see results
Use Cmd+Enter to run