Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 693 Bytes

File metadata and controls

30 lines (25 loc) · 693 Bytes

Description

Implement the function generateRange which takes three arguments (start, stop, step) and returns the range of integers from start to stop (inclusive) in increments of step.

Examples

(1, 10, 1) -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(-10, 1, 1) -> [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1]
(1, 15, 20) -> [1]

Note

  • start < stop
  • step > 0

My Solution

def generate_range(min, max, step)
  min.step(max, step).to_a
end

Better/Alternative solution from Codewars

def generate_range(min, max, step)
  (min..max).step(step).to_a
end