Modo entrevista. Temporizador de 10 min, sin pistas y sin autocompletado
Reverse the words and capitalize them
MediaStrings10 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.
Ejemplos
reverseAndCapitalize('India is great')Devuelve 'Great Is India'
reverseAndCapitalize('hello WORLD')Devuelve 'World Hello'
reverseAndCapitalize(' one two ')Devuelve 'Two One'
Preguntada en EPAM · Fuente
Cargando el editor…
- Entrada
reverseAndCapitalize('India is great')Esperado'Great Is India' - Entrada
reverseAndCapitalize('hello WORLD')Esperado'World Hello' - Entrada
reverseAndCapitalize('')Esperado''
Las pruebas ocultas se ejecutan al enviar