Created
November 20, 2020 04:07
-
-
Save nivrith/e47db758a9d2ada85675e5a08db99353 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(); | |
| } | |
| size() { | |
| return this.data.length; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment