Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
Reverse the words and capitalize them
MoyenStrings10 min
Write a function reverseAndCapitalize(text) that returns the words of the string text in reverse order, and every word starts with a capital letter: 'India is great' becomes 'Great Is India'.
- Words in
textare separated by one or more spaces. There can be spaces at the start and at the end. A word is any group of characters without spaces, so it can contain'or-. - In every word the first character becomes upper case and all other characters become lower case:
'wORLD'becomes'World'. Change the letter case withtoUpperCase()andtoLowerCase(); a digit stays as it is. - The letters inside a word keep their order. Only the order of the words changes.
- In the result, words are separated by exactly one space, with no spaces at the start or the end.
- For an empty string or a string of spaces return
''.
You can split the string into words, reorder them and join them back.
Exemples
reverseAndCapitalize('India is great')Renvoie 'Great Is India'
reverseAndCapitalize('hello WORLD')Renvoie 'World Hello'
reverseAndCapitalize(' one two ')Renvoie 'Two One'
Posé chez EPAM · Source
Chargement de l'éditeur...
- Entrée
reverseAndCapitalize('India is great')Attendu'Great Is India' - Entrée
reverseAndCapitalize('hello WORLD')Attendu'World Hello' - Entrée
reverseAndCapitalize('')Attendu''
Les tests cachés se lancent à la soumission