# new MultiRangeObject(arg, rangeObject)
A multi-range object contains many RangeObjects. They are iterated over with the fastest moving index going over the right-most range object in array order. Each element of a multi range is a tuple of values from constituent ranges.
Parameters:
Name | Type | Description |
---|---|---|
arg |
RangeObject | Array.<RangeObject> | object | First range object, or array of range objects, or object with |
rangeObject |
RangeObject | If first argument is a RangeObject, subsquent arguments are range objects too. |
Example
r0 = new RangeObject(1,2)
r1 = new RangeObject(1,3)
mro = new MultiRangeObject(r0, r1)
mro.toArray()
// [ [ 1, 1 ], [ 1, 2 ], [ 1, 3 ], [ 2, 1 ], [ 2, 2 ], [ 2, 3 ] ]
Extends
Members
# hasRemainder
Boolean indicating whether any of the ranges in this multi-range object has a remainder. See RangeObject#hasRemainder.
Methods
# filter(…args)
Converts range to an Array and then calls filter(...args)
on it.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
any |
<repeatable> |
Same args as you would pass to Array#filter |
- Overrides:
# nthValue(n)
Returns a tuple of values from the ranges given by this multi range object.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | index of multi-range tuple to return |
Example
r0 = new RangeObject(1,2)
r1 = new RangeObject(1,3)
mro = new MultiRangeObject(r0, r1)
mro.toArray()
// [ [ 1, 1 ], [ 1, 2 ], [ 1, 3 ], [ 2, 1 ], [ 2, 2 ], [ 2, 3 ] ]
mro.nthValue(2)
// [ 1, 3 ]
# slice(startopt, endopt)
Generate array from range starting at value start
and ending at value end
via nthValue
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
number |
<optional> |
0 | index to start slice |
end |
number |
<optional> |
index to end slice, return rest of array if not provided. |
- Overrides:
# toString()
Create string representation of this MultiRangeObject
Example
"[object MultiRangeObject ' + this.ranges.length + ']"