Your Submissions
You haven't submitted any code for this challenge yet. Solve the problem by passing all the test cases, and your submissions will appear here.
xxxxxxxxxx31
class EventEmitter { subscriptions = new Map(); subscribe(eventName, callback) { if (!this.subscriptions.has(eventName)) { this.subscriptions.set(eventName, new Set()); } const subscriptions = this.subscriptions.get(eventName); const callbackObj = { callback }; subscriptions.add(callbackObj); return { release: () => { subscriptions.delete(callbackObj); if (subscriptions.size === 0) { delete this.subscriptions.eventName; } }, }; } emit(eventName, args) { const subscriptions = this.subscriptions.get(eventName); if (subscriptions) { subscriptions.forEach((cbObj) => { cbObj.callback.apply(this, args); });OUTPUT
Results will appear here.