freeCodeCamp/Data Structures/queueClass.js

26 lines
605 B
JavaScript
Raw Normal View History

2023-08-22 02:58:23 +02:00
// https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/create-a-queue-class
function Queue() {
var collection = [];
this.print = function () {
console.log(collection);
};
// Only change code below this line
this.enqueue = function (elem) {
collection.push(elem);
};
this.dequeue = function () {
return collection.shift();
};
this.front = function () {
return collection[0];
};
this.size = function () {
return collection.length;
};
this.isEmpty = function () {
return !collection.length;
};
// Only change code above this line
}