Course of Raku / Advanced / More about built-in types / Strings / Exercises / Acronym
Solution: Acronym
Here is a possible solution to the task.
Code
my $phrase = 'hyper text markup language';
my $acronym = '';
for $phrase.words -> $word {
$acronym ~= $word.substr(0, 1);
}
say $acronym.uc;🦋 You can find the source code in the file acronym.raku.
Output
HTMLComments
$phrase.wordsgives the list of words. The loop takes the first character of each one withsubstr(0, 1)and appends it to$acronym.Once all the initials are collected,
ucturns the result into upper case:HTML.
Course navigation
← Acronym | The domain part →