Coding Interview Data Structure Questions: Create a Priority Queue Class

In this challenge you will be creating a Priority Queue. A Priority Queue is a special type of Queue with one primary difference, that you can set the priority in the queue as either high represented by 0 or low represented by an integer greater than 0 during the enqueue process. Item priority will override the placement order: that is, an item enqueue with a higher priority than any preceding items will be moved to the front of the queue. If items have equal priority, then placement order will decide their dequeue order. For instance:

collection = [[‘taco’,1]]

PriorityQueue.enqueue([‘kitten’, 1]);

console.log([…PriorityQueue])

// would be [[‘taco’, 1], [‘kitten’, 1]]

// not [[‘kitten’, 1], [‘taco’, 1]]

For this challenge, you will create an object called PriorityQueue. You will need to add an enqueue method for adding items with a priority, a dequeue method for popping off the front item, a size method to return the number of items in the queue, and finally an isEmpty method that will return true or false if the queue is empty.