JSFiddle - React, Tailwind, and code Playground
JavaScript
console.clear();
let c = (...s) => console.log(...s)
// Queues
function Queue() {
let collection = [];
this.print = function() {
c(collection);
}
this.enqueue = function(item) {
collection.push(item);
}
this.dequeue = function() {
return collection.shift();
}
this.front = function() {
return collection[0];
}
this.isEmpty = function() {
return (collection.length == 0);
}
this.size = function() {
return collection.length;
}
}
let q = new Queue();
q.enqueue('a');
q.enqueue('d');
q.enqueue('r');
q.print();
q.dequeue();
q.print();