Function mapRepeat

  • Category

    Returns an iterable that uses a function that generates values a given number of times.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • valueFn: ((increment) => T)

      A function that returns each value to fill the array with

        • (increment): T
        • Parameters

          • increment: number

          Returns T

    • times: number

      The number of times to repeat the value

    Returns Iterable<T>

    An iterable that repeats value times number of times

    Iterable

    Example

    [...mapRepeat((increment) => increment ** 2, 5)]; // [0, 1, 4, 9, 16]
    

    See

    • mapFill to do the same thing but return an array
    • repeat to do the same thing but with a given value