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 Flatten | |
def self.flatten input, answer = [] | |
# Function is called recursively if element of input is an Array. | |
# If element is not an Array, it is pushed to answer. | |
input.each do |element| | |
element.is_a?(Array) ? self.flatten(element, answer) : answer << element | |
end | |
answer | |
end | |
end |
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
for i in 1..100 | |
puts i if i % 2 != 0 | |
end |