Create a new range from 2 values.
Time complexity: O(1)
Space complexity: O(1)
The lower bound of this range
The upper bound of this range
If lower
is greater than upper
const range = new Range(100, 200);
The lower bound of this range
The upper bound of this range
An iterable that contains this.lower
and this.upper
.
Time complexity: O(1)
Space complexity: O(1)
const [lower, upper] = range;
Check whether a given range has the same lower and upper bounds as this one.
Time complexity: O(1)
Space complexity: O(1)
Range to compare
Whether the other range has the same lower and upper bounds as this one
const a = new Range(0, 100);
const b = new Range(0, 100);
a.equals(a); // true
a.equals(b); // true
const a = new Range(0, 100);
const b = new Range(150, 150);
a.equals(b); // true
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)
const range = new Range(100, 200);
console.log(range.has(150)); // true
console.log(range.has(300)); // false
Check if this range and a given range have any intersection.
Time complexity: O(1)
Space complexity: O(1)
Range to compare
Whether the ranges intersect
const a = new Range(100, 200);
const b = new Range(150, 250);
a.intersects(b); // true
const a = new Range(100, 200);
const b = new Range(300, 400);
a.intersects(b); // false
Check whether this range contains the given range
Time complexity: O(1)
Space complexity: O(1)
Range to compare
Whether this range contains the given range
const a = new Range(0, 100);
const b = new Range(25, 75);
a.isSubRange(b); // true
b.isSubRange(a); // false
Check whether a given range contains this range.
Time complexity: O(1)
Space complexity: O(1)
Range to compare
Whether this range is contained within the other one
const a = new Range(0, 100);
const b = new Range(25, 75);
a.isSuperrange(b); // false
b.isSuperrange(a); // true
Static
fromCreate a new range from the first 2 values of an iterable.
Time complexity: O(1)
Space complexity: O(1)
The iterable to create a range from
A new range
const range = Range.from([100, 200]);
Generated using TypeDoc
A range between 2 values.