Tracks
/
Rust
Rust
/
Exercises
/
Reverse String
Reverse String

Reverse String

Easy

Introduction

Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming.

For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance.

Instructions

Your task is to reverse a given string.

Some examples:

  • Turn "stressed" into "desserts".
  • Turn "strops" into "sports".
  • Turn "racecar" into "racecar".

Bonus

Test your function on this string: uüu and see what happens. Try to write a function that properly reverses this string. Hint: grapheme clusters

To get the bonus test to run, remove the ignore flag (#[ignore]) from the last test, and execute the tests with:

cargo test --features grapheme

You will need to use external libraries (a crate in rust lingo) for the bonus task. A good place to look for those is crates.io, the official repository of crates. Please remember that only a limited set of crates is supported by our test runner. The full list is in this file under the section [dependencies].

Check the documentation for instructions on how to use external crates in your projects.

Edit via GitHub The link opens in a new window or tab
Rust Exercism

Ready to start Reverse String?

Sign up to Exercism to learn and master Rust with 98 exercises, and real human mentoring, all for free.

Deep Dive into Reverse String!

Explore 14 different ways to reverse a string, exploring a range of topics including Unicode Codepoints, Graphemes, Stack vs Heap allocations, and pointers. Kick back and enjoy 45mins of learning with Jeremy and Erik.