My code for priority queue is failing one test: “The priority queue should return items with a higher priority before items with a lower priority and return items in first-in-first-out order otherwise.”
this.enqueue = function(element){
if(this.isEmpty())
this.collection.push(element);
else if(this.collection[this.size() - 1][1] > element[1])
this.collection.push(element);
else if(this.collection[0][1] <= element[1])
this.collection.unshift(element)
else{
for(let i = 1; i < this.size(); i++){
if(element[1] >= this.collection[i][1]){
this.collection.splice(i, 0, element);
break;
}
}
}
}
this.dequeue = function(){
return this.collection.pop();
}
this.front = function(){
return this.collection[this.collection.length];
}
this.isEmpty = function(){
return this.collection.length == 0;
}
this.size = function(){
return this.collection.length;
}