getRange()

Returns a range of numbers by the specified `step` from minimum to the given `value` of the specified `Range` object

Range.prototype.getRange()

The getRange() method returns a range of numbers by the specified step from minimum to the given value of the specified Range object.

range.class.ts
public getRange(value: number = this.max): Readonly<Array<number>> {
  const range = [];
  let current: number = this.min;
  while (current <= value) {
    current <= this.max && range.push(current), (current += this.#step);
  }
  return range;
}

Parameters

value:number= this.max

Optional maximum range value of number type of returned array by default it's the maximum range.

Return type

Returns

The return value is a range of numbers of a read-only Array from minimum to the given value.

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);

// Returns (9) [3, 6, 9, 12, 15, 18, 21, 24, 27] of readonly number[]
range.getRange();

// Returns (3) [3, 6, 9] of readonly number[]
range.getRange(10);

Last updated