Last active
March 20, 2017 14:37
-
-
Save fee1good/191002973fae8b9917e10d7e6838334c to your computer and use it in GitHub Desktop.
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 Numbers | |
def initialize(str) | |
@str = str | |
@str_arr = str.split("").map(&:to_i) #создаю массив цифр из строки | |
end | |
def take_sequence | |
@mega_result = Array.new | |
@str_arr.each_index do |i| | |
result = Array.new | |
if @str_arr.length - 1 == i | |
return | |
else | |
if @str_arr[i] == @str_arr[i + 1] - 1 | |
@mega_result << result.push(@str_arr[i], @str_arr[i + 1]) | |
else | |
next | |
end | |
end | |
end | |
@mega_result | |
end | |
end | |
p Numbers.new("1235689").take_sequence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment