Skip to the content

Reverse the text

Problem

Write a function that takes a text and returns it backwards. With "hello" you return "olleh". Spaces count like any other character, so they move too.

If the text is empty, you return an empty text.

Examples

  • "hello" → "olleh"

  • "a" → "a"

  • With spaces

    "Ann Lee" → "eeL nnA"

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def reverse_text(text):
    pass

JavaScript

function reverseText(text) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →