Skip to content

Instantly share code, notes, and snippets.

@nivrith
Created November 20, 2020 04:09
Show Gist options
  • Select an option

  • Save nivrith/d3a87a23fd7b7a6f9e2df32fa0084586 to your computer and use it in GitHub Desktop.

Select an option

Save nivrith/d3a87a23fd7b7a6f9e2df32fa0084586 to your computer and use it in GitHub Desktop.
Make your own iterables in javascript
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;
}
isMember(item: T) {
if (this.data.indexOf(item) !== -1) {
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment