Course of Raku / Addendum 🆕 / Bringing it together / Mixed mini-projects / Exercises / A text histogram
Solution: A text histogram
Here is a possible solution to the task.
Code
my %sales = apples => 5, pears => 3, plums => 8;
for %sales.sort -> $pair {
say "{$pair.key}: { '#' x $pair.value }";
}🦋 You can find the source code in the file histogram.raku.
Output
apples: #####
pears: ###
plums: ########Comments
- The string repetition operator
xbuilds each bar:'#' x 5is#####. The value simply becomes the bar length.