Heap Sort in js