function colon
colon(
start: number,
end: number,
step?: number,
): array

Generates an array of numbers from start to end with a specified step.

Creates an array of numbers starting from start, ending at end, and incrementing by step. If step is not provided, it defaults to 1.

Examples

Generate array from 1 to 10 with step 1

import { assertEquals } from "jsr:@std/assert";

assertEquals(colon(1, 10, 1), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

Generate array from 10 to 1 with step 1 (should return empty array)

import { assertEquals } from "jsr:@std/assert";

assertEquals(colon(10, 1, 1), []);

Generate array from -5 to 5 with step 2

import { assertEquals } from "jsr:@std/assert";

assertEquals(colon(-5, 5, 2), [-5, -3, -1, 1, 3, 5]);

Generate array from -7 to 14 with step 2

import { assertEquals } from "jsr:@std/assert";

assertEquals(colon(-7, 14, 2), [-7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13]);

Parameters

start: number

The starting value of the array.

end: number

The ending value of the array.

optional
step: number = 1

The step value between elements. Defaults to 1.

Return Type

An array of numbers from start to end with a step of step.

Throws

If fewer than two arguments are provided.