Nodejs Array Heap heapify()

Here you can find the source of heapify()

Method Source Code

Array.prototype.heapify = function(){
    var len = this.length,
        i = Math.floor(len/2);/*from   ww  w .j av a  2s  . c  om*/

    while(i >= 0){
        this.sift(i--);
    }

    return this;
}

function heapSort(arr){
    var len = arr.length,
        end = len - 1;

    arr.heapify();

    return arr;
}

Related

  1. heapify()
    Array.prototype.heapify = function() {
      this.forEach(function(num, index){
        if (index != 0) {
          var childPos = index;
          while (childPos > 0) {
            var parentPos = this.parentPos(childPos);
            if (this[childPos] > this[parentPos]) {
              this.swap(childPos, parentPos);
              childPos = parentPos;
    ...