Heap

Heap data structure. Can be used as a min or max heap with a custom comparison function.

Constructor

new Heap(items, func)

Create a new Heap.
Parameters:
NameTypeDescription
itemsArray.<any>Items to add
funcfunctionFunction for comparing two items

Methods

add(item)

Add an item to the heap. Will append the item to the end of the array and heapify after.
Parameters:
NameTypeDescription
itemanyItem to add

hasCustom(func) → {boolean}

Check if a value exists in the Heap, using a specific function. Because of the custom function, the search must be done by iterating over every single value in the raw array.
Parameters:
NameTypeDescription
funcfunctionFunction to check with
Returns:
Whether or not the Heap contains a value fulfilling the requirements of the custom function
Type: 
boolean

peek() → {any}

Peek at the root value of the Heap.
Returns:
Root value of the Heap
Type: 
any

pop() → {any}

Pop the root of the Heap. Will swap the last item with the root, remove the original, and heapify after.
Returns:
Root value of the Heap
Type: 
any