Function mapRepeat

  • 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: number) => T

      A function that returns each value to fill the array with

    • times: number

      The number of times to repeat the value

    Returns Iterable<T>

    An iterable that repeats value times number of times

    Iterable

    [...mapRepeat((increment) => increment ** 2, 5)]; // [0, 1, 4, 9, 16]
    
    • mapFill to do the same thing but return an array
    • repeat to do the same thing but with a given value