JS Built-ins
StringString.prototype.padEndintermediate

String.prototype.padEnd() β€” fill string is truncated if needed

πŸ“– Usage Example
'5'.padEnd(3, '0')       // β†’ '500'
'hello'.padEnd(8, '-')   // β†’ 'hello---'
'hi'.padEnd(2)           // β†’ 'hi'

Use padEnd() to pad the end of a string with a fill character until it reaches the target length.

String.prototype.padEnd() β€” Truncated Fill

If the fill string is longer than needed, it is truncated.

'ab'.padEnd(5, 'XYZ') β†’ 'abXYZ' (fill truncated to exactly fit) 'ab'.padEnd(6, 'XYZ') β†’ 'abXYZX'

Challenge: Implement padPattern(str, len) that pads with '123'.

padPattern('ab', 7) // β†’ 'ab12312'
πŸ’‘ Hints (1)
  • β€’ The fill string cycles: `"123"` β†’ `"123123..."` truncated to fit the gap.