Skip to content

Instantly share code, notes, and snippets.

@sayradley
Created December 3, 2018 07:45
Show Gist options
  • Save sayradley/2ae17a8fbbcf988868c6693f0abcfc4f to your computer and use it in GitHub Desktop.
Save sayradley/2ae17a8fbbcf988868c6693f0abcfc4f to your computer and use it in GitHub Desktop.
flatten array
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