src/index.js
function getHighestRanking(item, keys, value, options) {
  if (!keys) {
    return {
      rank: getMatchRanking(item, value, options),
      keyIndex: -1,
      keyThreshold: options.threshold,
    }
  }
  const valuesToRank = getAllValuesToRank(item, keys)
  return valuesToRank.reduce(
    ({rank, keyIndex, keyThreshold}, {itemValue, attributes}, i) => {
      let newRank = getMatchRanking(itemValue, value, options)
      const {minRanking, maxRanking, threshold} = attributes
      if (newRank < minRanking && newRank >= rankings.MATCHES) {
        newRank = minRanking
      } else if (newRank > maxRanking) {
        newRank = maxRanking
      }
      if (newRank > rank) {
        rank = newRank
        keyIndex = i
        keyThreshold = threshold
      }
      return {rank, keyIndex, keyThreshold}
    },
    {rank: rankings.NO_MATCH, keyIndex: -1, keyThreshold: options.threshold},
  )
}
function getHighestRanking(item, keys, value, options) {
  if (!keys) {
    return {
      rank: getMatchRanking(item, value, options),
      keyIndex: -1,
      keyThreshold: options.threshold,
    }
  }
  const valuesToRank = getAllValuesToRank(item, keys)
  return valuesToRank.reduce(
    ({rank, keyIndex, keyThreshold}, {itemValue, attributes}, i) => {
      let newRank = getMatchRanking(itemValue, value, options)
      const {minRanking, maxRanking, threshold} = attributes
      if (newRank < minRanking && newRank >= rankings.MATCHES) {
        newRank = minRanking
      } else if (newRank > maxRanking) {
        newRank = maxRanking
      }
      if (newRank > rank) {
        rank = newRank
        keyIndex = i
        keyThreshold = threshold
      }
      return {rank, keyIndex, keyThreshold}
    },
    {rank: rankings.NO_MATCH, keyIndex: -1, keyThreshold: options.threshold},
  )
}
function getHighestRanking ( item , keys , value , options ) { if ( ! keys ) { return { rank : getMatchRanking ( item , value , options ) , keyIndex : - 1 , keyThreshold : options . threshold , } } const valuesToRank = getAllValuesToRank ( item , keys ) return valuesToRank . reduce ( ( { rank , keyIndex , keyThreshold } , { itemValue , attributes } , i ) => { let newRank = getMatchRanking ( itemValue , value , options ) const { minRanking , maxRanking , threshold } = attributes if ( newRank < minRanking && newRank >= rankings . MATCHES ) { newRank = minRanking } else if ( newRank > maxRanking ) { newRank = maxRanking } if ( newRank > rank ) { rank = newRank keyIndex = i keyThreshold = threshold } return { rank , keyIndex , keyThreshold } } , { rank : rankings . NO_MATCH , keyIndex : - 1 , keyThreshold : options . threshold } , ) }
Gets the highest ranking for value for the given item based on its values for the given keys
@param {*} item - the item to rank
@param {Array} keys - the keys to get values from the item for the ranking
@param {String} value - the value to rank against
@param {Object} options - options to control the ranking
@return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking
Gets the highest ranking for value for the given item based on its values for the given keys