JavaScript has no priority queue. Write a class Heap.
new Heap(compare): compare(a, b) works like the comparator of sort, and a negative result means a comes out before b. The default is ascending numbers, (a, b) => a - bpush(item) adds an itempop() removes and returns the item that comes first, or undefined when the heap is emptypeek() returns it without removing, or undefined when emptysize is a getter, used as heap.size, with no parenthesespush and pop must be O(log n); the tests push and pop a hundred thousand items