Modo entrevista. Cronômetro de 10 min, sem dicas e sem autocompletar
Reverse the words and capitalize them
MédiaStrings10 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.
Exemplos
reverseAndCapitalize('India is great')Retorna 'Great Is India'
reverseAndCapitalize('hello WORLD')Retorna 'World Hello'
reverseAndCapitalize(' one two ')Retorna 'Two One'
Cobrada em EPAM · Fonte
Carregando o editor...
- Entrada
reverseAndCapitalize('India is great')Esperado'Great Is India' - Entrada
reverseAndCapitalize('hello WORLD')Esperado'World Hello' - Entrada
reverseAndCapitalize('')Esperado''
Os testes ocultos rodam no envio