Course of Raku / Addendum 🆕 / Working with data / Text and strings / Exercises / Reverse the word order

Solution: Reverse the word order

Here is a possible solution to the task.

Code

my $sentence = 'Raku is really nice';

say $sentence.words.reverse.join(' ');

🦋 You can find the source code in the file reverse-words.raku.

Output

nice really is Raku

Comments

  1. .words breaks the sentence into a list, .reverse flips the list order, and .join(' ') glues the words back together with single spaces.

Course navigation

Reverse the word order   |   Count the vowels