Skip to content

Instantly share code, notes, and snippets.

@robertomiranda
Created May 18, 2016 21:17
Show Gist options
  • Save robertomiranda/c169fb45f93e7017d129b222fc56d2ef to your computer and use it in GitHub Desktop.
Save robertomiranda/c169fb45f93e7017d129b222fc56d2ef to your computer and use it in GitHub Desktop.
def flatten(elem)
if elem.is_a?(Array)
if elem.empty?
[]
else
head, *tail = elem
flatten(head) + flatten(tail)
end
else
[elem]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment