@jiminp/tooltool
    Preparing search index...

    Function arrayGetOrExtendWith

    • Gets the element at the given index, extending via a factory function if out of bounds.

      Type Parameters

      • T extends object

        Element type.

      Parameters

      • arr: T[]

        The dense array.

      • index: number

        Integer array index from 0 through 2 ** 32 - 2.

      • f: (index: number) => T

        Factory called with each new index to create an entry.

      Returns T

      The element at index.

      If index is not a valid array index.

      The factory is not called for an existing entry. Unlike arrayGetOrExtend, this accepts entries of any object type, including built-ins and class instances.

      const dates: Date[] = [];
      arrayGetOrExtendWith(dates, 1, (i) => new Date(i)); // Date at timestamp 1