JS Built-ins
← String105 / 195
StringString.prototype.repeatbeginner

String.prototype.repeat() β€” empty string input

πŸ“– Usage Example
'ab'.repeat(3)    // β†’ 'ababab'
'-'.repeat(5)     // β†’ '-----'
'x'.repeat(0)    // β†’ ''

Use repeat() to create a new string with the original repeated a specified number of times.

String.prototype.repeat() β€” Empty String

Repeating an empty string any number of times always yields an empty string.

Challenge: Implement repeatEmpty(n) that repeats an empty string n times and returns the result.

repeatEmpty(100) // β†’ ''
repeatEmpty(0)   // β†’ ''
πŸ’‘ Hints (1)
  • β€’ An empty string has no characters to repeat, so the result is always `""`.