Modo entrevista. Temporizador de 5 min, sin pistas y sin autocompletado
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.
Ejemplos
truncate('Automation testing', 10)Devuelve 'Automatio…'
truncate('Hello', 5)Devuelve 'Hello'
truncate('Hello!', 5)Devuelve 'Hell…'
Cargando el editor…
- Entrada
truncate('Automation testing', 10)Esperado'Automatio…' - Entrada
truncate('Hello', 5)Esperado'Hello' - Entrada
truncate('Hello!', 5)Esperado'Hell…'
Las pruebas ocultas se ejecutan al enviar