Code Lab

Modo entrevista. Temporizador de 3 min, sin pistas y sin autocompletado

Function types

FácilTypeScript 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.

Ejemplos

greet('Ann', 2)

Devuelve 'Hi, Ann! Hi, Ann!'

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

Devuelve 'Hi, Bob!'

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

Devuelve ''

Zero repeats give an empty string.

Fuente

Función
Cargando el editor…
  1. Entradagreet('Ann', 2)
    Esperado'Hi, Ann! Hi, Ann!'
  2. Entradagreet('Bob', 1)
    Esperado'Hi, Bob!'

Las pruebas ocultas se ejecutan al enviar