Modo entrevista. Temporizador de 10 min, sin pistas y sin autocompletado
Words in reverse order
MediaStrings10 min
Write a function reverseWords(sentence) that returns the words of the string in reverse order. The words themselves are not reversed: 'I Love Java' becomes 'Java Love I'.
- Words are separated by one or more spaces.
- In the result words are separated by exactly one space, with no spaces at the start or the end.
- Punctuation stays part of the word.
- For an empty string or a string of spaces return
''.
Ejemplos
reverseWords('I Love Java')Devuelve 'Java Love I'
reverseWords(' one two ')Devuelve 'two one'
Preguntada en Mphasis · Fuente
Cargando el editor…
- Entrada
reverseWords('I Love Java')Esperado'Java Love I' - Entrada
reverseWords('Hello')Esperado'Hello' - Entrada
reverseWords('')Esperado''
Las pruebas ocultas se ejecutan al enviar