- Iterations
- 1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class Series def initialize(series) @series = series end def slices(n) if n > @series.length raise ArgumentError, 'Slice length is longer than series' end # convert to list of ints series = @series.split('').collect(&:to_i) (0...series.length - n + 1).map { |x| series[x...x + n] } end end |

class Series
def initialize(series)
@series = series
end
def slices(n)
if n > @series.length
raise ArgumentError, 'Slice length is longer than series'
end
# convert to list of ints
series = @series.split('').collect(&:to_i)
(0...series.length - n + 1).map { |x| series[x...x + n] }
end
end

## Comments

You're not logged in right now. Please login via GitHub to comment