Fork this gist and submit a link with your solution
First, install globally expect
(you need it to test your code):
npm install -global expect
Then, whenever you are done, simply do the following to know if you passed (or failed):
$ node ./test.js
Create an event emitter that goes like this:
const emitter = new Emitter();
Its instance allows you to subscribe to some event by passing a callback function
emitter.subscribe('myEvent', firstArgument => console.log('a callback!'));
...any times you want...
emitter.subscribe('myEvent', (firstArgument, secondArgument) => console.log('another callback!'));
You can emit the event you want and pass any number of arguments
emitter.emit('myEvent', 'firstArgument', 'secondArgument');
Make the return from the subscribe method to return a function that allows you to release that subscription:
const sub1 = emitter.subscribe('myEvent', () => console.log('a callback!'));
sub1();
...but all other subscriptions shall remain intact
Make the emit method return an array with every return value for each subscription callback
Good luck! πͺπΌπͺπΌπͺπΌ
I'd still rather prefer to make an
npm install
of local dependencies than a globalnpm install
of a package :P