• Category

    Returns an array with the elements of the iterable repeated a provided number of times.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The iterable to cycle

    • times: number

      The number of times to repeat the elements of iterable

    Returns Iterable<T>

    An array with the elements of iterable repeated times number of times

    Iterable

    Example

    [...cycle(['a', 'b'], 2)]; // ['a', 'b', 'a', 'b']