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

String.prototype.repeat() β€” zero count

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

Calling .repeat(0) always returns an empty string regardless of the original string.

Challenge: Implement isRepeatEmpty(str) that returns true if repeating str zero times gives an empty string.

isRepeatEmpty('hello') // β†’ true
isRepeatEmpty('')      // β†’ true
πŸ’‘ Hints (1)
  • β€’ `str.repeat(0)` is always `""` regardless of what `str` is.