const heapOptions = {cmp: (a, b) => a < b // max heap comparator "Default"}// You can remove type specification and it will default to numberconst h = new Heap([], heapOptions);
Array of elements to push into the heap
Optional
Heap options
Get the current size of the heap
const h = Heap();const size = h.push(1).push(2).push(5).size(); // 3
Retrieve the top element in the heap
const h = Heap();const peak = h.push(1).push(2).push(3).peak(); // 3
pop the top of the heap
self reference
const h = Heap();h.push(1).push(2).push(3).pop();
Push data into the heap
const h = Heap();h.push(1).push(2).push(3);
View the heap
const h = Heap();h.push(1).push(2).push(5).view(); //[ 5 , 2 , 1 ]
Generated using TypeDoc
Example