build/ical.js
function(list, seekVal, cmpfunc) {
    if (!list.length)
      return 0;

    var low = 0, high = list.length - 1,
        mid, cmpval;

    while (low <= high) {
      mid = low + Math.floor((high - low) / 2);
      cmpval = cmpfunc(seekVal, list[mid]);

      if (cmpval < 0)
        high = mid - 1;
      else if (cmpval > 0)
        low = mid + 1;
      else
        break;
    }

    if (cmpval < 0)
      return mid; // insertion is displacing, so use mid outright.
    else if (cmpval > 0)
      return mid + 1;
    else
      return mid;
  }
function(list, seekVal, cmpfunc) {
    if (!list.length)
      return 0;

    var low = 0, high = list.length - 1,
        mid, cmpval;

    while (low <= high) {
      mid = low + Math.floor((high - low) / 2);
      cmpval = cmpfunc(seekVal, list[mid]);

      if (cmpval < 0)
        high = mid - 1;
      else if (cmpval > 0)
        low = mid + 1;
      else
        break;
    }

    if (cmpval < 0)
      return mid; // insertion is displacing, so use mid outright.
    else if (cmpval > 0)
      return mid + 1;
    else
      return mid;
  }
function ( list , seekVal , cmpfunc ) { if ( ! list . length ) return 0 ; var low = 0 , high = list . length - 1 , mid , cmpval ; while ( low <= high ) { mid = low + Math . floor ( ( high - low ) / 2 ) ; cmpval = cmpfunc ( seekVal , list [ mid ] ) ; if ( cmpval < 0 ) high = mid - 1 ; else if ( cmpval > 0 ) low = mid + 1 ; else break ; } if ( cmpval < 0 ) return mid ; // insertion is displacing, so use mid outright. else if ( cmpval > 0 ) return mid + 1 ; else return mid ; }
Find the index for insertion using binary search.

@param {Array} list            The list to search
@param {?} seekVal             The value to insert
@param {function(?,?)} cmpfunc The comparison func, that can
compare two seekVals
@return {Number}               The insert position
Find the index for insertion using binary search .