function(index, match) {
    var returnValue = -1,
        itemType = match ? RETAIN : FILTER,
        self = this;

    this._findOperation(index, function(operation, operationIndex, rangeStart, rangeEnd, seenInSubArray) {
      var newOperation, splitOperation;

      if (itemType === operation.type) {
        ++operation.count;
      } else if (index === rangeStart) {
        // insert to the left of `operation`
        self._operations.splice(operationIndex, 0, new Operation(itemType, 1));
      } else {
        newOperation = new Operation(itemType, 1);
        splitOperation = new Operation(operation.type, rangeEnd - index + 1);
        operation.count = index - rangeStart;

        self._operations.splice(operationIndex + 1, 0, newOperation, splitOperation);
      }

      if (match) {
        if (operation.type === RETAIN) {
          returnValue = seenInSubArray + (index - rangeStart);
        } else {
          returnValue = seenInSubArray;
        }
      }

      self._composeAt(operationIndex);
    }, function(seenInSubArray) {
      self._operations.push(new Operation(itemType, 1));

      if (match) {
        returnValue = seenInSubArray;
      }

      self._composeAt(self._operations.length-1);
    });

    return returnValue;
  }
function(index, match) {
    var returnValue = -1,
        itemType = match ? RETAIN : FILTER,
        self = this;

    this._findOperation(index, function(operation, operationIndex, rangeStart, rangeEnd, seenInSubArray) {
      var newOperation, splitOperation;

      if (itemType === operation.type) {
        ++operation.count;
      } else if (index === rangeStart) {
        // insert to the left of `operation`
        self._operations.splice(operationIndex, 0, new Operation(itemType, 1));
      } else {
        newOperation = new Operation(itemType, 1);
        splitOperation = new Operation(operation.type, rangeEnd - index + 1);
        operation.count = index - rangeStart;

        self._operations.splice(operationIndex + 1, 0, newOperation, splitOperation);
      }

      if (match) {
        if (operation.type === RETAIN) {
          returnValue = seenInSubArray + (index - rangeStart);
        } else {
          returnValue = seenInSubArray;
        }
      }

      self._composeAt(operationIndex);
    }, function(seenInSubArray) {
      self._operations.push(new Operation(itemType, 1));

      if (match) {
        returnValue = seenInSubArray;
      }

      self._composeAt(self._operations.length-1);
    });

    return returnValue;
  }
function ( index , match ) { var returnValue = - 1 , itemType = match ? RETAIN : FILTER , self = this ; this . _findOperation ( index , function ( operation , operationIndex , rangeStart , rangeEnd , seenInSubArray ) { var newOperation , splitOperation ; if ( itemType === operation . type ) { ++ operation . count ; } else if ( index === rangeStart ) { // insert to the left of `operation` self . _operations . splice ( operationIndex , 0 , new Operation ( itemType , 1 ) ) ; } else { newOperation = new Operation ( itemType , 1 ) ; splitOperation = new Operation ( operation . type , rangeEnd - index + 1 ) ; operation . count = index - rangeStart ; self . _operations . splice ( operationIndex + 1 , 0 , newOperation , splitOperation ) ; } if ( match ) { if ( operation . type === RETAIN ) { returnValue = seenInSubArray + ( index - rangeStart ) ; } else { returnValue = seenInSubArray ; } } self . _composeAt ( operationIndex ) ; } , function ( seenInSubArray ) { self . _operations . push ( new Operation ( itemType , 1 ) ) ; if ( match ) { returnValue = seenInSubArray ; } self . _composeAt ( self . _operations . length - 1 ) ; } ) ; return returnValue ; }
Track that an item was added to the tracked array.

@method addItem

@param {number} index The index of the item in the tracked array.
@param {boolean} match `true` iff the item is included in the subarray.

@return {number} The index of the item in the subarray.
Track that an item was added to the tracked array .