Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion
Truncate a string
FacileStrings5 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.
Exemples
truncate('Automation testing', 10)Renvoie 'Automatio…'
truncate('Hello', 5)Renvoie 'Hello'
truncate('Hello!', 5)Renvoie 'Hell…'
Chargement de l'éditeur...
- Entrée
truncate('Automation testing', 10)Attendu'Automatio…' - Entrée
truncate('Hello', 5)Attendu'Hello' - Entrée
truncate('Hello!', 5)Attendu'Hell…'
Les tests cachés se lancent à la soumission