Skip to content

Instantly share code, notes, and snippets.

@tcstory
Created October 17, 2016 10:26
Show Gist options
  • Save tcstory/474e8d3f5a36bac76de44d7ebbece15e to your computer and use it in GitHub Desktop.
Save tcstory/474e8d3f5a36bac76de44d7ebbece15e to your computer and use it in GitHub Desktop.
class Queue {
constructor() {
this._items = [];
}
enqueue(element) {
if (Array.isArray(element)) {
this._items.push(...element);
} else {
this._items.push(element);
}
}
dequeue() {
return this._items.shift();
}
front() {
return this._items[0];
}
isEmpty() {
return this._items.length === 0;
}
get size() {
return this._items.length;
}
clear() {
return this._items = [];
}
print() {
console.log(this._items.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment