jty
    Preparing search index...

    Function inRange

    • Checks if a number x is within a given range (inclusive). This function also serves as a type guard, narrowing the type to number.

      At least one of min or max must be provided. If min happens to be larger than max, it swaps them and works gracefully.

      Parameters

      • x: number

        The number to check.

      • Optionalmin: number

        The minimum value of the range (inclusive). If undefined, only the max is checked.

      • Optionalmax: number

        The maximum value of the range (inclusive). If undefined, only the min is checked.

      Returns x is number

      true if x is within the specified range, false otherwise.

      if x is not a number.

      if either min or max are defined, but are not numbers.

      if neither min nor max are provided.

      inRange(5, 0, 10) => true
      inRange(5, 5, 10) => true
      inRange(5, 0, 5) => true
      inRange(5, 4) => true
      inRange(5, 6) => false // 5 >= 6
      inRange(5, 10, 2) => true
      inRange(5, undefined, 4) => false // 5 <= 4