Code Lab

Modo entrevista. Temporizador de 10 min, sin pistas y sin autocompletado

Reverse a sentence with emoji

MediaStrings10 min

Write a function reverseSentence(sentence) that returns the string sentence with all its characters in reverse order.

  • Every character counts: letters (also letters such as é), spaces, punctuation. Spaces at the start and the end are kept, they just move to the other end: ' a ' gives ' a ', 'ab ' gives ' ba'.
  • An emoji such as 😀 or 🚀 stays whole: 'Hi 😀' gives '😀 iH'.
  • The input has only single emoji, no flags and no emoji made of several parts.
  • An empty string gives ''.

Watch out: split('') cuts an emoji in half, and the result shows broken symbols. for...of and the spread syntax [...sentence] go by whole characters.

Ejemplos

reverseSentence('I Love Java and Selenium Webdriver')

Devuelve 'revirdbeW muineleS dna avaJ evoL I'

reverseSentence('Hi 😀')

Devuelve '😀 iH'

Preguntada en Capgemini · Fuente

Cargando el editor…
  1. EntradareverseSentence('I Love Java and Selenium Webdriver')
    Esperado'revirdbeW muineleS dna avaJ evoL I'
  2. EntradareverseSentence('Hello')
    Esperado'olleH'
  3. EntradareverseSentence('')
    Esperado''
  4. EntradareverseSentence('Hi 😀')
    Esperado'😀 iH'

Las pruebas ocultas se ejecutan al enviar