static compareClosestPreferLower(outputValue, bestValue, candidateValue) {
    const {BETTER, EQUAL, WORSE} = shaka.util.PeriodCombiner.BetterOrWorse;

    // If one is the exact match for the output value, and the other isn't,
    // prefer the one that is the exact match.
    if (bestValue == outputValue && outputValue != candidateValue) {
      return WORSE;
    } else if (candidateValue == outputValue && outputValue != bestValue) {
      return BETTER;
    }

    if (bestValue > outputValue) {
      if (candidateValue <= outputValue) {
        // Any smaller-or-equal-to-output value is preferable to a
        // bigger-than-output value.
        return BETTER;
      }

      // Both "best" and "candidate" are greater than the output.  Take
      // whichever is closer.
      if (candidateValue - outputValue < bestValue - outputValue) {
        return BETTER;
      } else if (candidateValue - outputValue > bestValue - outputValue) {
        return WORSE;
      }
    } else {
      // The "best" so far is less than or equal to the output.  If the
      // candidate is bigger than the output, we don't want it.
      if (candidateValue > outputValue) {
        return WORSE;
      }

      // Both "best" and "candidate" are less than or equal to the output.
      // Take whichever is closer.
      if (outputValue - candidateValue < outputValue - bestValue) {
        return BETTER;
      } else if (outputValue - candidateValue > outputValue - bestValue) {
        return WORSE;
      }
    }

    return EQUAL;
  }
Compare the best value so far with the candidate value and the output
value.  Decide if the candidate is better, equal, or worse than the best
so far.  Any value less than or equal to the output is preferred over a
larger value, and closer to the output is better than farther.

This provides us a generic way to choose things that should match as
closely as possible, like resolution, frame rate, audio channels, or
sample rate.  If we have to go higher to make a match, we will.  But if
the user selects 480p, for example, we don't want to surprise them with
720p and waste bandwidth if there's another choice available to us.

@param {number} outputValue
@param {number} bestValue
@param {number} candidateValue
@return {shaka.util.PeriodCombiner.BetterOrWorse}