getRangeOfStep()
Returns a range of numbers by the specified step from the minimum to the given `step` of a specified `Range` object
Range.prototype.getRangeOfStep()
Range.prototype.getRangeOfStep()
The getRangeOfStep()
method returns a range of numbers by the specified step
from the minimum to the given step
of a specified Range
object.
public getRangeOfStep(step: number): Readonly<Array<number>> {
const range = [];
if (step > 0 && step <= this.steps) {
for (let value = 0; value < step; value++) {
range.push(this.min + value * this.#step);
}
}
return range;
}
Parameters
Step of number
type is the maximum range of the returned array
.
The value must be less or equal to the number of range steps
.
Return type
Returns
The return value is a range of numbers of a read-only Array
from minimum to step of the given step
if the given step
is within a range, otherwise an empty Array
.
Example usage
// Example usage.
import { Method } from '@angular-package/range';
// Create new instance.
// Returns Range {min: 3, max: 27, value: 10} of Range<3, 27, 3>.
const range = new Range(3, 27, 10, 3);
// Maximum steps is 9.
range.steps;
// Get range to step 3. Returns (3) [3, 6, 9]
range.getRangeToStep(3);
// Get range to step 9. Returns (9) [3, 6, 9, 12, 15, 18, 21, 24, 27]
range.getRangeToStep(9);
Last updated