Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
Words in reverse order
MoyenStrings10 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
''.
Exemples
reverseWords('I Love Java')Renvoie 'Java Love I'
reverseWords(' one two ')Renvoie 'two one'
Posé chez Mphasis · Source
Chargement de l'éditeur...
- Entrée
reverseWords('I Love Java')Attendu'Java Love I' - Entrée
reverseWords('Hello')Attendu'Hello' - Entrée
reverseWords('')Attendu''
Les tests cachés se lancent à la soumission