Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.