utilitish - v0.0.10
    Preparing search index...

    Interface ArrayConstructor

    interface ArrayConstructor {
        new ArrayConstructor(arrayLength?: number): any[];
        new ArrayConstructor<T>(arrayLength: number): T[];
        new ArrayConstructor<T>(...items: T[]): T[];
        zip(...arrays: any[][]): any[][];
        range(start: number, end?: number, step?: number): number[];
        repeat<T>(length: number, value: T | (() => T)): T[];
        create<T, Dims extends number[]>(
            valueOrFactory: T | (() => T),
            ...sizes: Dims,
        ): MultiDimensionalArray<WidenLiterals<T>, Dims>;
        (arrayLength?: number): any[];
        <T>(arrayLength: number): T[];
        <T>(...items: T[]): T[];
    }
    • Parameters

      • OptionalarrayLength: number

      Returns any[]

    • Type Parameters

      • T

      Parameters

      • arrayLength: number

      Returns T[]

    • Type Parameters

      • T

      Parameters

      • ...items: T[]

      Returns T[]

    Index

    Constructors

    Methods

    Constructors

    • Parameters

      • OptionalarrayLength: number

      Returns any[]

    • Type Parameters

      • T

      Parameters

      • arrayLength: number

      Returns T[]

    • Type Parameters

      • T

      Parameters

      • ...items: T[]

      Returns T[]

    Methods

    • Combines multiple arrays element-wise, similar to Python's itertools.zip_longest.

      Parameters

      • ...arrays: any[][]

        Arrays to zip together

      Returns any[][]

      A new array where each element is an array containing the elements at the same index from each input array. Missing elements are undefined.

      Array.zip([1, 2], ['a', 'b', 'c']);
      // => [[1, 'a'], [2, 'b'], [undefined, 'c']]
    • Generates a sequence of numbers, similar to Python's range.

      Parameters

      • start: number

        First number, or the length if end is not provided

      • Optionalend: number

        Last number (excluded)

      • Optionalstep: number

        Step between numbers (can be negative)

      Returns number[]

      An array containing the generated sequence

      Array.range(5);
      // => [0, 1, 2, 3, 4]
      Array.range(2, 10, 2);
      // => [2, 4, 6, 8]
    • Creates an array filled with the same value or with values generated by a factory function.

      Type Parameters

      • T

        Type of the array elements

      Parameters

      • length: number

        Length of the array (must be a non-negative integer)

      • value: T | (() => T)

        Value or function generating the value

      Returns T[]

      The filled array

      Array.repeat(3, 'x');
      // => ['x', 'x', 'x']
      Array.repeat(3, () => Math.random());
      // => [0.12, 0.45, 0.78] (values will differ)
    • Creates an array filled with a given value or generated using a factory function. Supports creating multi-dimensional arrays by passing multiple sizes.

      Type Parameters

      • T
      • Dims extends number[]

      Parameters

      • valueOrFactory: T | (() => T)

        The value to fill the array with, or a factory function producing values.

      • ...sizes: Dims

        Sizes for each dimension (1D => one number, 2D => two numbers, etc.).

      Returns MultiDimensionalArray<WidenLiterals<T>, Dims>

      A multi-dimensional array of the specified depth filled with the given values.

      // 1D array with primitive values
      const arr1 = Array.create('x', 5);
      // type: string[]
      // value: ['x', 'x', 'x', 'x', 'x']
      // 1D array with random numbers
      const arr2 = Array.create(() => Math.random(), 5);
      // type: number[]
      // value: [0.12, 0.87, 0.45, 0.76, 0.33] (values will differ)
      // 2D array (matrix)
      const arr3 = Array.create(0, 2, 3);
      // type: number[][]
      // value: [[0, 0, 0], [0, 0, 0]]
      // 2D array with distinct objects
      const arr4 = Array.create(() => ({ id: 0 }), 2, 3);
      // type: { id: number }[][]
      // value: [
      // [{ id: 0 }, { id: 0 }, { id: 0 }],
      // [{ id: 0 }, { id: 0 }, { id: 0 }]
      // ]
      • If sizes.length === 0, returns [].
      • If valueOrFactory is a primitive, all cells contain the same value.
      • If valueOrFactory is a function, it is called for each cell to produce a fresh value.
      • sizes should be integers >= 0; negative or non-integer values are not supported.
      • This method is static and must be called on Array, not on an instance.