Last active
November 20, 2020 07:10
-
-
Save nivrith/47cd970b1d621637a71c1477817517f0 to your computer and use it in GitHub Desktop.
Make your own iterables in javascript
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
| export class Queue<T> { | |
| constructor(private length: number, private data: T[] = []) {} | |
| add(record) { | |
| const length = this.data.unshift(record); | |
| if (length > this.length) { | |
| this.remove(); | |
| } | |
| } | |
| remove() { | |
| this.data.pop(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment