Modo entrevista. Cronômetro de 3 min, sem dicas e sem autocompletar
Narrowing a type
FácilTypeScript types3 min
The function formatId(id: string | number) gets an order id. If it is a number, return a string with # in front, for example '#42'. If it is a string, return it in upper case.
Do not change the signature and the code at the bottom.
Exemplos
formatId(42)Retorna '#42'
formatId('ab-7')Retorna 'AB-7'
formatId('15')Retorna '15'
Função
Carregando o editor...
- Entrada
formatId(42)Esperado'#42' - Entrada
formatId('ab-7')Esperado'AB-7' - Entrada
formatId('15')Esperado'15'
Os testes ocultos rodam no envio