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

String.prototype.repeat() β€” count of 1

πŸ“– 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() β€” Count 1

str.repeat(1) returns a new string equal to the original.

Challenge: Implement repeatOnce(str) that returns the string repeated once.

repeatOnce('hello') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ `str.repeat(1)` is equivalent to copying the string.