I'm trying to populate an array with sizes that are measured in whole and half numbers (i.e. 10, 10.5, 11, 11.5, 12). So far I have:
(10..12).map{ |size| [size, size + 0.5] }.flatten[0...-1]
Does a more eloquent way of doing this exist in Ruby without having to flatten and remove the last element?
My personal favorite:
>> (10..12).step(0.5).to_a
=> [10.0, 10.5, 11.0, 11.5, 12.0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With