How can I make an array of 30 min intervals to 8 hours. so this ish:
[30, 60, 90, all-the-way-to, 480]
You can use a Range and the step method, then convert it to an Array:
(30..480).step(30).to_a
The result is:
[30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480)
take so you can use it based on how many elements you want. (30..).step(30).take(16).to_a30.step(nil, 30).take(16) or 30.step(480, 30).to_a or 0.step(480, 30).drop(1).Your arguments are
increment = 30
duration = 480 # 8*60
You could use
increment.step(by: increment, to: duration).to_a
#=> [ 30, 60, 90, 120, 150, 180, 210, 240,
# 270, 300, 330, 360, 390, 420, 450, 480]
which reads well. Numeric#step, when used without a block, returns an enumerator, which is why .to_a is needed.
Option selecting (Enumerable#select) from the range:
stop = 480
step = 30
(step..stop).select { |n| n % step == 0 }
#=> [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480]