Can anybody help me figure out why my code wont pass all tests?
function PriorityQueue () {
this.collection = [];
this.printCollection = function() {
console.log(this.collection);
};
this.isEmpty = () => this.collection.length === 0 ? true:false;
this.size = () => this.collection.length;
this.enqueue = (arr) => arr[1]===1? this.collection.unshift(arr):this.collection.push(arr);
this.dequeue = () => this.collection.shift()[0]
this.front = () => this.collection[0][0];
}
Specially the last 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.
If I test with the following
var pq = new PriorityQueue;
pq.enqueue(['rabbit', 2]);
pq.enqueue(['dog', 2]);
pq.enqueue(['kitten', 2]);
pq.enqueue(['human', 1]);
console.log(pq.dequeue())
pq.printCollection()
console.log(pq.dequeue())
pq.printCollection()
console.log(pq.dequeue())
pq.printCollection()
console.log(pq.dequeue())
pq.printCollection()
I get
human
[ [ 'rabbit', 2 ], [ 'dog', 2 ], [ 'kitten', 2 ] ]
rabbit
[ [ 'dog', 2 ], [ 'kitten', 2 ] ]
dog
[ [ 'kitten', 2 ] ]
kitten
[]
and if I copy the solution I get exactly the same thing.
Thanks
Thanks