Created
December 3, 2018 07:45
-
-
Save sayradley/2ae17a8fbbcf988868c6693f0abcfc4f to your computer and use it in GitHub Desktop.
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
def flatten(array, flatten_array = []) | |
array.each do |element| | |
if element.instance_of?(Array) | |
flatten(element, flatten_array) | |
else | |
flatten_array << element | |
end | |
end | |
flatten_array | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment