The rangeCheck function in TypeScript is used to validate if an index is within a specified range and throws a RangeError with a custom message if it is out of bounds.

  • Parameters

    • index: number

      The index parameter represents the value that you want to check if it falls within a specified range.

    • min: number

      The min parameter represents the minimum value that the index should be compared against in the rangeCheck function.

    • max: number

      The max parameter in the rangeCheck function represents the maximum value that the index parameter is allowed to have. If the index is greater than this max value, a RangeError will be thrown.

    • Optionalmessage: string = 'Index out of bounds.'

      The message parameter is a string that represents the error message to be thrown if the index is out of bounds. By default, if no message is provided when calling the rangeCheck function, the message "Index out of bounds." will be used.

    Returns void