Skip to content

Instantly share code, notes, and snippets.

@quezacoatl
Created April 3, 2018 06:51
Show Gist options
  • Save quezacoatl/17dbee0f3b979b5362181c611a1a8578 to your computer and use it in GitHub Desktop.
Save quezacoatl/17dbee0f3b979b5362181c611a1a8578 to your computer and use it in GitHub Desktop.
Flatten array in Ruby
def flatten(arr, flat=[])
arr.each_with_object(flat) do |item, result|
if item.is_a?(Array)
flatten(item, flat)
else
result << item
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment