0 of 6 problems solved0%
4 of 6

Pad Left with a Default Width

Default parameters let callers omit values while still receiving sensible behavior. When you write width: number = 0, callers can pass just the string and the function will use 0.

You’ll implement left-padding: return the string with width spaces added on the left.

Your Task

  • Complete the function padLeft(s: string, width: number = 0): string.
  • If width is 0, return s unchanged.
  • Otherwise, return ' '.repeat(width) + s.

Examples

  • padLeft('x', 3) → ' x'
  • padLeft('x') → 'x'