percolateDown function is exactly same as heappop. This won't create a heap of out an array. If the initial array is [3,5,4,10,2,1]. After percolateDown's execution array will be [3,2,1,10,5,4] which is still not a heap. Edit: for some one looking at it in future. In heapify function, instead of running from first node to last. It should run from last to first so (let i = last;i>=0;i--)