simplify.js
function heapDown(i) {
    var w = heapWeight(i)
    while(true) {
      var tw = w
      var left  = 2*i + 1
      var right = 2*(i + 1)
      var next = i
      if(left < heapCount) {
        var lw = heapWeight(left)
        if(lw < tw) {
          next = left
          tw = lw
        }
      }
      if(right < heapCount) {
        var rw = heapWeight(right)
        if(rw < tw) {
          next = right
        }
      }
      if(next === i) {
        return i
      }
      heapSwap(i, next)
      i = next      
    }
  }
function heapDown(i) {
    var w = heapWeight(i)
    while(true) {
      var tw = w
      var left  = 2*i + 1
      var right = 2*(i + 1)
      var next = i
      if(left < heapCount) {
        var lw = heapWeight(left)
        if(lw < tw) {
          next = left
          tw = lw
        }
      }
      if(right < heapCount) {
        var rw = heapWeight(right)
        if(rw < tw) {
          next = right
        }
      }
      if(next === i) {
        return i
      }
      heapSwap(i, next)
      i = next      
    }
  }
function heapDown ( i ) { var w = heapWeight ( i ) while ( true ) { var tw = w var left = 2 * i + 1 var right = 2 * ( i + 1 ) var next = i if ( left < heapCount ) { var lw = heapWeight ( left ) if ( lw < tw ) { next = left tw = lw } } if ( right < heapCount ) { var rw = heapWeight ( right ) if ( rw < tw ) { next = right } } if ( next === i ) { return i } heapSwap ( i , next ) i = next } }
Bubble element i down the heap
Bubble element i down the heap