When completing the Leetcode daily challenge for last month, there were quite a few problems where using a priority queue was the optimal solution, but, JavaScript does not have heap or priority queue data structures built into it. When I went to implement my own priority queue class, I learned this secret that made everything much easier:
Trying to declare a PriorityQueue class errors out on Leetcode because they have not only that but also MinPriorityQueue and MaxPriorityQueue implemented for you to use. At the time I couldn’t find the documentation for this, but, I just found this link that details the environments for every language on Leetcode.
If you are trying to solve one of these problems, you might just need the .enqueue(), .dequeue(), and .isEmpty() methods. But, the documentation for the version of datastructures-js/priority-queue that they are using is available here if you end up needing more than that.
The environment for JS also includes datastructures-js/queue as well as Lodash if you want to use a regular queue or any of the Lodash utility functions.