Gets the value at the specified index in the range.
The index of the value to get.
The value at the specified index.
Gets the average of the values in the range.
Clamps a value to the range. If the value is less than the start of the range, the start of the range is returned. If the value is greater than the end of the range, the end of the range is returned. Otherwise, the value is returned.
The value to clamp.
The clamped value.
Checks whether the range contains a value or another range.
The value or range to check for containment.
true
if the range contains the value or range and false
otherwise.
The number of values in the range.
The end value of the range.
Gets an iterator over the values in the range.
An iterator over the values in the range.
Checks whether the range is equal to another range.
The range to compare to.
true
if the ranges are equal and false
otherwise.
The unique ID of the range.
Gets the index of a value in the range.
The value to get the index of.
The index of the value or -1
if the value is not in the range.
Checks whether the range intersects with another range.
The range to check for intersection with.
true
if the ranges intersect and false
otherwise.
An identifier for the object type.
The difference between the start and end values.
Maps a value from the range to a value in another range.
The value to map.
The range to map to.
The mapped value.
const range1 = range(5, 10);
const range2 = range(0, 100);
expect(range1.mapValue(6, range2)).toBe(20);
The start value of the range.
The step between values in the range. Defaults to 1.
Gets the sum of all values in the range.
Gets the range's values as an array.
The range as an array.
Gets the range as a JSON-encodable object.
The range as a JSON object.
Gets the range as a string in the format [start, end, step]
.
The range as a string.
Applies a transform function to the range.
The function to apply to the start and end values.
Optional
step_transformer: ((step) => number)The function to apply to the step. Optional. If not provided, the step will not be transformed.
The transformed range.
const range1 = range(0, 10);
expect(range1.transform((value) => value * 2, (step) => step * 2).equals(range(0, 20, 2))).toBe(true);
Gets the union of the range with another range. The union is the smallest range that contains both ranges. The step size of the ranges must be the same.
The range to union with.
The union of the ranges.
An error if the ranges have different step sizes.
Wraps a value to the range. The result is the value modulo the length of the range.
The value to wrap.
The wrapped value.
Generated using TypeDoc
A range of numbers represented by an object with a start, end, and step, as well as methods for performing operations on the range.