Given a number, my code should return all the even numbers between 1 and the number, and print them in the following format:
22
4444
666666
etc...
This is the code so far:
def pattern(n)
n == 1 ? "" : arr = (1..n).select {|i| i if i % 2 == 0}.each {|item| return (item.to_s * item)}
end
With any number greater than four, it will only return the following:
22
I think that this may have something to do with the return in the block. However, when using print or puts, this returns an individual array element as follows:
[2]
Ideas for a way around this so that I can achieve the desired output?