Modo entrevista. Cronômetro de 5 min, sem dicas e sem autocompletar
Truncate a string
FácilStrings5 min
Write a function truncate(text, maxLength). If the string is longer than maxLength, cut it and put one … character at the end, so the result is exactly maxLength long. A string that fits in maxLength comes back unchanged.
Exemplos
truncate('Automation testing', 10)Retorna 'Automatio…'
truncate('Hello', 5)Retorna 'Hello'
truncate('Hello!', 5)Retorna 'Hell…'
Carregando o editor...
- Entrada
truncate('Automation testing', 10)Esperado'Automatio…' - Entrada
truncate('Hello', 5)Esperado'Hello' - Entrada
truncate('Hello!', 5)Esperado'Hell…'
Os testes ocultos rodam no envio