Search code examples
rubyarrays

incremental array in ruby, 0..40, [10, 20, 30, 40]


How can I offset this array so it only outputs every ten numbers?

(0...40)
[10,20,30,40]

Solution

  • Use the step method for this:

    10.step(40,10)
    

    The first argument is the number you want to count up to, with the second argument being the "steps" that you take to get there.