PriorityQueue challenge

Tell us what’s happening:
passing all test except the last one. no idea why. any help would be greatly appreciated .

thank you in advance

Your code so far


function PriorityQueue () {
this.collection = [];
this.printCollection = function() {
  console.log(this.collection);
};
// Only change code below this line
this.enqueue = (item) => {
  if (this.isEmpty()) {
    this.collection = [item];
    return;
  }
  const queue = this.collection;
  const priority = item[1];
  let i = this.collection.findIndex(function (item) {
    return priority < item[1];
  });
  if (i === -1) {
    this.collection = [...queue, item]
  } else {
    this.collection = [
      ...queue.slice(0, i), item, ...queue.slice(i)
    ]
  }
}
this.dequeue = () => {
  if (this.isEmpty()) return;
  this.collection = this.collection.slice(1)
  return this.front()
}
this.size = () => {
  return this.collection.length
}
this.front = () => {
  if (!this.isEmpty()) return this.collection[0][0];
}
this.isEmpty = () => {
  return this.size() <= 0;
}
// Only change code above this line
}
const myQ = new PriorityQueue()
myQ.collection = [['human', 1], ['kitten', 2], ['dog', 2], ['rabbit', 2], ['tiger', 3]]
console.log('front, ', myQ.front())
console.log('enqueue, ', `['wolf', 0]`)
myQ.enqueue(['wolf', 2.5])
console.log('front, ', myQ.front())
console.log('dequeued, ', myQ.dequeue())
console.log('front, ', myQ.front())
myQ.printCollection()

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.

Challenge: Create a Priority Queue Class

Link to the challenge:

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.

Okay so a queue is always FIFO

priority queueu return items with high priority

befor low prior items

and return items in fifo

like they explained

[[‘kitten’, 2], [‘dog’, 2], [‘rabbit’, 2]]

Here the second value (an integer) represents item priority. If we enqueue [‘human’, 1] with a priority of 1 (assuming lower priorities are given precedence) it would then be the first item to be dequeued. The collection would look like this:

[[‘human’, 1], [‘kitten’, 2], [‘dog’, 2], [‘rabbit’, 2]].

so what u need to do is check the 2nd item and check it with the following ones
in this case
[‘wolf’, 0], [[‘human’, 1], [‘kitten’, 2], [‘dog’, 2], [‘rabbit’, 2], [‘tiger’, 3]]
Hope it helps :3