index.js
function difference(arrayA, arrayB) {
  var maxLength = _.max([ arrayA.length, arrayB.length ]);

  for (var i = 0, j = 0; i < maxLength; i += 1, j += 1) {
    if (arrayA[i] !== arrayB[j]) {
      if (arrayB[i-1] === arrayA[i]) {
        j -= 1;
      } else if (arrayB[i+1] === arrayA[i]) {
        j += 1;
      } else {
        return arrayA[i];
      }
    }
  }
}
function difference(arrayA, arrayB) {
  var maxLength = _.max([ arrayA.length, arrayB.length ]);

  for (var i = 0, j = 0; i < maxLength; i += 1, j += 1) {
    if (arrayA[i] !== arrayB[j]) {
      if (arrayB[i-1] === arrayA[i]) {
        j -= 1;
      } else if (arrayB[i+1] === arrayA[i]) {
        j += 1;
      } else {
        return arrayA[i];
      }
    }
  }
}
function difference ( arrayA , arrayB ) { var maxLength = _ . max ( [ arrayA . length , arrayB . length ] ) ; for ( var i = 0 , j = 0 ; i < maxLength ; i += 1 , j += 1 ) { if ( arrayA [ i ] !== arrayB [ j ] ) { if ( arrayB [ i - 1 ] === arrayA [ i ] ) { j -= 1 ; } else if ( arrayB [ i + 1 ] === arrayA [ i ] ) { j += 1 ; } else { return arrayA [ i ] ; } } } }
Given two arrays of backbone models, with at most one model added and one model removed from each, return the model in arrayA that is not in arrayB or undefined.
Given two arrays of backbone models with at most one model added and one model removed from each return the model in arrayA that is not in arrayB or undefined .