Function repeat

  • Repeats the given string n times.

    If n is less than 1, an empty string is returned, or if the string is an empty string, the original string is returned unchanged.

    Parameters

    • str: string

      The string to repeat.

    • n: number

      The number of times to repeat the string.

    Returns string

    • The repeated string, or an empty string if n is less than 1.
    repeat('abc', 0); // ''
    repeat('abc', 2); // 'abcabc'