EventEmitter Counter
NodeJS
Medium
3 views
Problem Description
Use EventEmitter to count events and print the total.
Output Format
Print integer.
Constraints
Emit 'hit' event three times.
Official Solution
const { EventEmitter } = require('events');
const ee = new EventEmitter();
let count = 0;
ee.on('hit', () => { count += 1; });
ee.emit('hit');
ee.emit('hit');
ee.emit('hit');
console.log(count);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!