Create a Priority Queue Class test failure

Tell us what’s happening:
Hey folks,

I’m doing the priority queue challenge and I seem to be running into the “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.” test failure

I have checked my code against the solution 1 and I can see that solution swaps around some of the items in the queue when calling enqueue and dequeue and then passes the tests (kitten, dog, rabbit becomes kitten, rabbit, dog)

Maybe I’m missing something, but I believe according to not-so-clear requirement, my code passes the test

Your code so far


function PriorityQueue () {
this.collection = [];
this.printCollection = function() {
  console.log(this.collection);
};
// Only change code below this line
this.enqueue = function(priorityItemArray) {
   this.collection.unshift(priorityItemArray)
   for (let queueItem in this.collection) {
      queueItem = parseInt(queueItem);
      let swap = []; 
      if (queueItem + 1 == this.collection.length) break;
      if (this.collection[queueItem][1] >= this.collection[queueItem + 1][1]) {
        swap = this.collection[queueItem + 1]
        this.collection[queueItem + 1] = this.collection[queueItem]
        this.collection[queueItem] = swap
      } 
   }

   return this.collection;
}

this.dequeue = function() {
  let val = this.collection.shift()
  return val[0];
}

this.front = function() {
  return this.collection[0]
}

this.size = function() {
  return this.collection.length;
}

this.isEmpty = function() {
  return (this.collection == 0)
}

// Only change code above this line
}


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Create a Priority Queue Class

Link to the challenge:

I’m wondering if it is because I’m using shift/unshift rather than pop/push…