src/index.js
function sortRankedItems(a, b) {
  const aFirst = -1
  const bFirst = 1
  const {rank: aRank, index: aIndex, keyIndex: aKeyIndex} = a
  const {rank: bRank, index: bIndex, keyIndex: bKeyIndex} = b
  const same = aRank === bRank
  if (same) {
    if (aKeyIndex === bKeyIndex) {
      return aIndex < bIndex ? aFirst : bFirst
    } else {
      return aKeyIndex < bKeyIndex ? aFirst : bFirst
    }
  } else {
    return aRank > bRank ? aFirst : bFirst
  }
}
function sortRankedItems(a, b) {
  const aFirst = -1
  const bFirst = 1
  const {rank: aRank, index: aIndex, keyIndex: aKeyIndex} = a
  const {rank: bRank, index: bIndex, keyIndex: bKeyIndex} = b
  const same = aRank === bRank
  if (same) {
    if (aKeyIndex === bKeyIndex) {
      return aIndex < bIndex ? aFirst : bFirst
    } else {
      return aKeyIndex < bKeyIndex ? aFirst : bFirst
    }
  } else {
    return aRank > bRank ? aFirst : bFirst
  }
}
function sortRankedItems ( a , b ) { const aFirst = - 1 const bFirst = 1 const { rank : aRank , index : aIndex , keyIndex : aKeyIndex } = a const { rank : bRank , index : bIndex , keyIndex : bKeyIndex } = b const same = aRank === bRank if ( same ) { if ( aKeyIndex === bKeyIndex ) { return aIndex < bIndex ? aFirst : bFirst } else { return aKeyIndex < bKeyIndex ? aFirst : bFirst } } else { return aRank > bRank ? aFirst : bFirst } }
Sorts items that have a rank, index, and keyIndex
@param {Object} a - the first item to sort
@param {Object} b - the second item to sort
@return {Number} -1 if a should come first, 1 if b should come first
Note: will never return 0
Sorts items that have a rank index and keyIndex