const q = new Queue();
q.add(1);
q.remove(); // returns 1;
Simple Queue
class Queue {
constructor() {
this.data = [];
}
printData() {
console.log(JSON.stringify(this.data, null, 4));
}
add(record) {
this.data.unshift(record);
}
peek() {
const lastIndex = this.data.length > 0 ? this.data.length - 1 : 0;
return this.data[lastIndex];
}
remove() {
return this.data.pop();
}
}