Options
All
• Public
• Public/Protected
• All

# Class Range

A range between 2 values.

• Range

## Constructors

• Create a new range from 2 values.

Time complexity: O(1)

Space complexity: O(1)

throws

If `lower` is greater than `upper`

example
``````const range = new Range(100, 200);
``````

#### Parameters

• ##### lower: Comparable

The lower bound of this range

• ##### upper: Comparable

The upper bound of this range

## Properties

lower: Comparable
upper: Comparable

## Methods

• An iterable that contains `this.lower` and `this.upper`.

Time complexity: O(1)

Space complexity: O(1)

example
``````const [lower, upper] = range;
``````

#### Returns IterableIterator<Comparable>

• equals(range: Range): boolean
• Check whether a given range has the same lower and upper bounds as this one.

Time complexity: O(1)

Space complexity: O(1)

example
``````const a = new Range(0, 100);const b = new Range(0, 100);a.equals(a); // truea.equals(b); // true
``````
example
``````const a = new Range(0, 100);const b = new Range(150, 150);a.equals(b); // true
``````

#### Parameters

• ##### range: Range

Range to compare

#### Returns boolean

Whether the other range has the same lower and upper bounds as this one

• Returns `true` if `value` is within `this.lower` and `this.upper`, false otherwise. The `>=` and `<=` operators are used to compare `value`.

Time complexity: O(1)

Space complexity: O(1)

example
``````const range = new Range(100, 200);console.log(range.has(150)); // trueconsole.log(range.has(300)); // false
``````

#### Returns boolean

• intersects(range: Range): boolean
• Check if this range and a given range have any intersection.

Time complexity: O(1)

Space complexity: O(1)

example
``````const a = new Range(100, 200);const b = new Range(150, 250);a.intersects(b); // true
``````
example
``````const a = new Range(100, 200);const b = new Range(300, 400);a.intersects(b); // false
``````

#### Parameters

• ##### range: Range

Range to compare

#### Returns boolean

Whether the ranges intersect

• isSubrange(range: Range): boolean
• Check whether this range contains the given range

Time complexity: O(1)

Space complexity: O(1)

example
``````const a = new Range(0, 100);const b = new Range(25, 75);a.isSubRange(b); // trueb.isSubRange(a); // false
``````

#### Parameters

• ##### range: Range

Range to compare

#### Returns boolean

Whether this range contains the given range

• isSuperrange(range: Range): boolean
• Check whether a given range contains this range.

Time complexity: O(1)

Space complexity: O(1)

example
``````const a = new Range(0, 100);const b = new Range(25, 75);a.isSuperrange(b); // falseb.isSuperrange(a); // true
``````

#### Parameters

• ##### range: Range

Range to compare

#### Returns boolean

Whether this range is contained within the other one

• Create a new range from the first 2 values of an iterable.

Time complexity: O(1)

Space complexity: O(1)

example
``````const range = Range.from([100, 200]);
``````

#### Parameters

• ##### iterable: Iterable<Comparable>

The iterable to create a range from

#### Returns Range

A new range

Generated using TypeDoc