Is there a simple function in ruby to create sequences? For example, I want a sequence from 1 to 100 incrementing by 3. So
Function(1,100,increment = 3) = [1,4,7,10, ...,97,100]
Thanks!
Range#step
generates another enumerator with given step.
say (1..100).step(3).to_a
would be [1,4,7, ... , 97, 100]
alternatively
Numeric#step(limit,step)
does similar things,
say 1.step(100,3).to_a
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