node_modules/jade/jade.js
/**
   * Recursive implementation of binary search.
   *
   * @param aLow Indices here and lower do not contain the needle.
   * @param aHigh Indices here and higher do not contain the needle.
   * @param aNeedle The element being searched for.
   * @param aHaystack The non-empty array being searched.
   * @param aCompare Function which takes two elements and returns -1, 0, or 1.
   */
Recursive implementation of binary search.
@param aLow Indices here and lower do not contain the needle.
@param aHigh Indices here and higher do not contain the needle.
@param aNeedle The element being searched for.
@param aHaystack The non-empty array being searched.
@param aCompare Function which takes two elements and returns -1, 0, or 1.
Recursive implementation of binary search . @param aLow Indices here and lower do not contain the needle . @param aHigh Indices here and higher do not contain the needle . @param aNeedle The element being searched for . @param aHaystack The non - empty array being searched . @param aCompare Function which takes two elements and returns - 1 0 or 1 .
function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
       1. We find the exact element we are looking for.
       2. We did not find the exact element, but we can return the next
          closest element that is less than that element.
       3. We did not find the exact element, and there is no next-closest
          element which is less than the one we are searching for, so we
          return null.
    var mid = Math.floor((aHigh - aLow) / 2) + aLow;
    var cmp = aCompare(aNeedle, aHaystack[mid]);
    if (cmp === 0) {
       Found the element we are looking for.
      return aHaystack[mid];
    }
    else if (cmp > 0) {
       aHaystack[mid] is greater than our needle.
      if (aHigh - mid > 1) {
         The element is in the upper half.
        return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
      }
       We did not find an exact match, return the next closest one
       (termination case 2).
      return aHaystack[mid];
    }
    else {
       aHaystack[mid] is less than our needle.
      if (mid - aLow > 1) {
         The element is in the lower half.
        return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
      }
       The exact needle element was not found in this haystack. Determine if
       we are in termination case (2) or (3) and return the appropriate thing.
      return aLow < 0
        ? null
        : aHaystack[aLow];
    }
  }
function recursiveSearch ( aLow , aHigh , aNeedle , aHaystack , aCompare ) { var mid = Math . floor ( ( aHigh - aLow ) / 2 ) + aLow ; var cmp = aCompare ( aNeedle , aHaystack [ mid ] ) ; if ( cmp === 0 ) { return aHaystack [ mid ] ; } else if ( cmp > 0 ) { if ( aHigh - mid > 1 ) { return recursiveSearch ( mid , aHigh , aNeedle , aHaystack , aCompare ) ; } return aHaystack [ mid ] ; } else { if ( mid - aLow > 1 ) { return recursiveSearch ( aLow , mid , aNeedle , aHaystack , aCompare ) ; } return aLow < 0 ? null : aHaystack [ aLow ] ; } }
Recursive implementation of binary search.
Recursive implementation of binary search .
// This function terminates when one of the following is true: // //   1. We find the exact element we are looking for. // //   2. We did not find the exact element, but we can return the next //      closest element that is less than that element. // //   3. We did not find the exact element, and there is no next-closest //      element which is less than the one we are searching for, so we //      return null. // Found the element we are looking for. // aHaystack[mid] is greater than our needle. // The element is in the upper half. // We did not find an exact match, return the next closest one // (termination case 2). // aHaystack[mid] is less than our needle. // The element is in the lower half. // The exact needle element was not found in this haystack. Determine if // we are in termination case (2) or (3) and return the appropriate thing.