Last active
August 29, 2015 14:06
-
-
Save daifu/e12ab909987f0ccfc441 to your computer and use it in GitHub Desktop.
Flatten An Array
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(ary) | |
ret = [] | |
ary.each do |sub_ary| | |
if sub_ary.is_a?(Array) | |
ret += flatten(sub_ary) | |
else | |
ret << sub_ary | |
end | |
end | |
ret | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment