So first of all, the dequeue method does not take an argument, it merely removes the next item waiting to be removed from the queue. Knowing this, the logic of the deque method should be fairly simple now.
Your enqueue logic is too simple. That’s where all the work is done and what makes a priority queue special. Remember, you can’t just tack an element onto the end of the collection array (unless the array is currently empty). You have to take into account the priority of the element as well.
Perhaps the description of a priority queue in the challenge isn’t enough? I found this description which seems to do a pretty good job explaining how it works. The code examples are in C, but that’s OK, you just need a description, not actual code.
Also, you could click the “Get Help” button, which does give a little better explanation of how a priority queue works. Just don’t be tempted to look at the solution quite yet
What is ...val doing here? Remember, the input into the enqueue method is going to be an array of two elements (e.g ['kitten', 2]) where the first element is the value and the second is the priority integer. I’m not sure you need to put the array passed into this method into an array.
Also, what if collection is currently empty. I don’t see in your enqueue method that it handles this condition.
If you haven’t done so yet, I would highly recommend you install node on your computer. This will allow you to do all of your coding on your local computer, which will make it much easier to test your code as well.
It shows me this: 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. But, that should be enough, is there an article to read about this? I want to figure out his.