I need to write a method to create a simple text bar chart given a value and maxvalue. So barchart(4, 10) would return "XXXX------".
It’s obviously trivially simple to just code that, but I’m trying to learn more about ruby string methods.
The nest I could come up with was: if you want, for example, 4/10 (i.e. an output of "XXXX------"),
graph = "".ljust(4, 'X').ljust(10, '-')
But that seems goofy, I suspect there’s a more direct way?
Here’s another way using string multiplication:
Whether or not this is “less goofy” is undecided.