ruby - Fill array with element N times -
i want fill array 1 element 5 times. got far.
str = 1234 = [] 5.times { << str } puts # => 1234, 1234, 1234, 1234, 1234 it works feels not ruby way. can point me in right direction init array 5 times same value?
array.new(5, str) # => [1234, 1234, 1234, 1234, 1234]
by way, bad practice name variable str assigned value 1234. confusing.
ruby
No comments:
Post a Comment