0 of 6 problems solved0%
1 of 6

Greeter with Optional Count

A function type describes parameter types and the return type. Optional means the argument may be missing. When an optional value is missing, choose a simple default.

You will write a small greeter with an optional repeat count. Keep the output stable and avoid side effects.

type Printer = (msg: string, times?: number) => string;

Your Task

Define a function type and implement a greeter with an optional count.

  • Declare type Greeter = (name: string, times?: number) => string.
  • Implement greet: Greeter.
  • When times is missing, return "Hello, <name>!".
  • When times is given, repeat that greeting joined by a single space (e.g., 3 times).
  • Do not mutate inputs.