ixfx
    Preparing search index...

    Function ensureLength

    Returns a copy of an array with specified length - padded or truncated as needed.

    If the input array is too short, it will be expanded based on the expand strategy:

    • 'undefined': fill with undefined (default)
    • 'repeat': repeat array elements, starting from position 0
    • 'first': repeat with first element from data
    • 'last': repeat with last element from data

    Truncate:

    ensureLength([1,2,3], 2); // [1,2]
    

    Padded:

    ensureLength([1,2,3], 5, `undefined`); // [1,2,3,undefined,undefined]
    ensureLength([1,2,3], 5, `repeat`); // [1,2,3,1,2]
    ensureLength([1,2,3], 5, `first`); // [1,2,3,1,1]
    ensureLength([1,2,3], 5, `last`); // [1,2,3,3,3]

    Input array to expand

    Desired length

    Expand strategy

    Type of array

    • Type Parameters

      • V

      Parameters

      • data: readonly V[] | V[]
      • length: number
      • expand: "repeat" | "first" | "last"

      Returns V[]

    • Type Parameters

      • V

      Parameters

      • data: readonly V[] | V[]
      • length: number
      • Optionalexpand: "undefined"

      Returns (undefined | V)[]