Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a range of integers [min, max), i.e. min bound is inclusive, but max bound is exclusive.

Note that this class is immutable, create new instance if you need another range bounds.

Hierarchy

  • IntegerRange

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • Creates an instance of IntegerRange, rounds min and max values if those have decimal parts and swaps them if min > max.

    Parameters

    • min: number

      minimum range bound (inclusive)

    • max: number

      maximim range bound (exclusive)

    Returns IntegerRange

Properties

max

max: number

Represents maximum range bound (exclusive)

min

min: number

Represents minimum range bound (inclusive)

Static empty

empty: IntegerRange = new IntegerRange(0, 0)

Accessors

rangeLength

  • get rangeLength(): number

Methods

includes

  • includes(suspect: number): boolean
  • Retuns true if suspect is integer and it goes inside this IntegerRange.

    Parameters

    • suspect: number

      Value to test wheter it is inside this IntegerRange

    Returns boolean

random

  • random(): number

randomUniqueIntegers

  • randomUniqueIntegers(limit?: number): IterableIterator<number>
  • Returns IterableIterator over random unique integers within this range.

    remarks

    Iterator's inner algorithm has O(max - min) linear memory complexity in all cases, and O(1) time complexity to generate each successive random integer.

    copyright

    https://stackoverflow.com/a/196065/9259330

    Parameters

    • Default value limit: number = this.rangeLength

      The maximum amount of numbers to generate, which is max - min by default

    Returns IterableIterator<number>

Generated using TypeDoc