Last active
September 28, 2018 17:55
-
-
Save zeitnot/b62c7c623071f7d71fce8df870b91374 to your computer and use it in GitHub Desktop.
Ruby flatten array
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
module FlattenArray | |
def self.flatten(ar, flatten_array = []) | |
ar.each do |el| | |
next unless el | |
if el.kind_of?(Array) | |
flatten(el,flatten_array) | |
else | |
flatten_array << el | |
end | |
end | |
flatten_array | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment