function sortFieldsByIndex(userFields, index) {
  var indexFields = index.def.fields.map(getKey);

  return userFields.slice().sort(function (a, b) {
    var aIdx = indexFields.indexOf(a);
    var bIdx = indexFields.indexOf(b);
    if (aIdx === -1) {
      aIdx = Number.MAX_VALUE;
    }
    if (bIdx === -1) {
      bIdx = Number.MAX_VALUE;
    }
    return compare(aIdx, bIdx);
  });
}
// if they're in the index
if they're in the index
if they ' re in the index
function sortFieldsByIndex(userFields, index) {
  var indexFields = index.def.fields.map(getKey);
  return userFields.slice().sort(function (a, b) {
    var aIdx = indexFields.indexOf(a);
    var bIdx = indexFields.indexOf(b);
    if (aIdx === -1) {
      aIdx = Number.MAX_VALUE;
    }
    if (bIdx === -1) {
      bIdx = Number.MAX_VALUE;
    }
    return compare(aIdx, bIdx);
  });
}
function sortFieldsByIndex ( userFields , index ) { var indexFields = index . def . fields . map ( getKey ) ; return userFields . slice ( ) . sort ( function ( a , b ) { var aIdx = indexFields . indexOf ( a ) ; var bIdx = indexFields . indexOf ( b ) ; if ( aIdx === - 1 ) { aIdx = Number . MAX_VALUE ; } if ( bIdx === - 1 ) { bIdx = Number . MAX_VALUE ; } return compare ( aIdx , bIdx ) ; } ) ; }
if they're in the index
if they ' re in the index