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!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Range#stepgenerates another enumerator with given step.say
(1..100).step(3).to_awould be[1,4,7, ... , 97, 100]alternatively
Numeric#step(limit,step)does similar things,say
1.step(100,3).to_a