Created
August 1, 2016 13:07
-
-
Save HoneyryderChuck/8b2306d0cd33c064dfcf09dd62b267da to your computer and use it in GitHub Desktop.
alternative flatten
This file contains 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(a, elems=[]) | |
a.each do |e| | |
case e | |
when Array then flatten(e, elems) | |
else elems << e | |
end | |
end | |
el | |
end | |
#=> flatten([[1, 2,[3, 5]], 6]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment