Array
range

Generates a sequence of numbers starting at the first argument, progressing by the step argument, and stopping at the second argument.

Syntax

range(
  start: number,
  end: number,
  options?: number | { step: number; inclusive: false }
): number[]

The step value can be auto infered based on the start & end values.

The third argument can be either a step value or an options object.

Usage

import { range } from '@opentf/std';
 
range(start, end);

Examples

range() // It throws error
 
range(0) // It throws error
 
range(NaN, 0) // It throws error
 
range(0, 0) //=> []
 
range(0, 0, { inclusive: true }) //=> [0]
 
range(0, 5) //=> [0, 1, 2, 3, 4]
 
range(0, 5, { inclusive: true }) //=> [0, 1, 2, 3, 4, 5]
 
range(3, 9, { step: 3 }) //=> [3, 6]
 
range(0, -5) //=> [0, -1, -2, -3, -4]
 
range(0, -4, { step: -1 }) //=> [0, -1, -2, -3]
 
range(-10, -5) //=> [-10, -9, -8, -7, -6]
 
range(10, 12, { step: 0.5 }) //=> [10, 10.5, 11, 11.5]

Try