Created
March 21, 2020 22:12
-
-
Save smendoza787/fdc26aa6e2de0f529c83fb66aee7a8c0 to your computer and use it in GitHub Desktop.
Huey the Queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HueyTheQueue { | |
constructor() { | |
this.q = [] | |
} | |
enQ(...msgs) { | |
return this.q.push(...msgs) | |
} | |
deQ() { | |
if (this.q.length) { | |
return this.q.shift() | |
} | |
throw Error('Huey has no news for you.') | |
} | |
peek() { | |
return this.q[0] | |
} | |
length() { | |
return this.q.length | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment