My code for the Priority Queue Class is failing. I get the error “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.” I haven’t yet figured out why it’s not queueing in order. Everything else is green lighted. Any assistance/info would be greatly appreciated.
Here is my code below.
function PriorityQueue () {
this.collection = [];
this.printCollection = function() {
console.log(this.collection);
};
// Only change code below this line
this.size = () => {return this.collection.length;};
this.isEmpty = () => {return this.collection.length === 0;};
this.dequeue = () => {return this.collection.shift()[0];};
this.front = () => {return this.collection[0][0];};
this.enqueue = data => {
if(this.isEmpty()){
this.collection.push(data);
}
else {
let insertionpoint = 0;
while(insertionpoint < this.size() && this.collection[insertionpoint][1] < data[1]){
insertionpoint += 1;
}
this.collection.splice(insertionpoint,0,data);
}
};
// Only change code above this line
}