The init function only needs to run _sortNodeDown on all non-leaf nodes, e.g. i < heapArray.length / 2 (see https://stackoverflow.com/a/18742428/8594404). I think this was the intention, because of the Math.floor call; just forgot to divide by 2 ;)
|
for (let i = Math.floor(this.heapArray.length); i >= 0; --i) { |