How from array with numbers:
a = [4,1,3]
make array:
s = ["****","*","***"]
So each number corresponds to amount of stars in a cell
How from array with numbers:
a = [4,1,3]
make array:
s = ["****","*","***"]
So each number corresponds to amount of stars in a cell
You can use map
like so:
a = [4,1,3]
s = a.map { |count| '*' * count }
#=> ["****", "*", "***"]
If you are okay with array contents being replaced, then, following will do it:
a.fill {|i| "*" * a[i]}
#=> ["****", "*", "***"]