Created
May 18, 2016 21:17
-
-
Save robertomiranda/c169fb45f93e7017d129b222fc56d2ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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(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