Function mapFill

  • Category

    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) => T)

      A function that returns each value to fill the array with

        • (index): T
        • Parameters

          • index: number

          Returns T

    • length: number

      The length of the array

    Returns T[]

    The filled array

    Example

    mapFill(i => i + 1, 3); // [1, 2, 3]
    

    See

    • mapRepeat to do the same thing but return an iterable
    • fill to do the same thing but with a given value

    Array