Created
November 14, 2015 00:01
-
-
Save durrellchamorro/5320966876dd7220402b to your computer and use it in GitHub Desktop.
Series
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Series | |
attr_reader :digits | |
def initialize(string_of_digits) | |
@digits = string_of_digits.chars.map(&:to_i) | |
end | |
def slices(slice_size) | |
fail ArgumentError, "Slice size cannot exceed caller's digit size." if slice_size > digits.size | |
result = [] | |
until digits.size < slice_size | |
result << digits.slice(0, slice_size) | |
digits.shift(1) | |
end | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment