Implement a custom event emitter class with methods on, emit, and off.
HardProblem Statement
Implement a custom event emitter class with methods on, emit, and off.
Sample Input
Register and emit an event hello.
Sample Output
Hello, World!
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
class EventEmitter {
private events: { [key: string]: Function[] };
on(event: string, listener: Function): void {
// Your logic here
}
emit(event: string, ...args: any[]): void {
// Your logic here
}
off(event: string, listener: Function): void {
// Your logic here
}
}
Input
Register and emit an event hello.
Expected Output
Hello, World!