Function mapFill

  • Create a new array of a specified length and fill it using the given function.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • valueFn: (index: number) => T

      A function that returns each value to fill the array with

    • length: number

      The length of the array

    Returns T[]

    The filled array

    mapFill(i => i + 1, 3); // [1, 2, 3]
    
    • mapRepeat to do the same thing but return an iterable
    • fill to do the same thing but with a given value

    Array