Code Lab

Mode entretien. Minuteur de 3 min, sans indices ni autocomplétion

Function types

FacileTypeScript types3 min

The function greet(name, times) returns a string where the greeting Hi, <name>! is repeated times times, separated by spaces. Add the parameters with types, set the return type and write the function body.

Do not change the code at the bottom. Each line after @ts-expect-error must stay a type error.

Exemples

greet('Ann', 2)

Renvoie 'Hi, Ann! Hi, Ann!'

Two greetings with a space between them.
greet('Bob', 1)

Renvoie 'Hi, Bob!'

One greeting with no spaces around it.
greet('Ann', 0)

Renvoie ''

Zero repeats give an empty string.

Source

Fonction
Chargement de l'éditeur...
  1. Entréegreet('Ann', 2)
    Attendu'Hi, Ann! Hi, Ann!'
  2. Entréegreet('Bob', 1)
    Attendu'Hi, Bob!'

Les tests cachés se lancent à la soumission