Last active
September 25, 2015 13:50
-
-
Save carlosgaldino/424aa556541a1c6fd9eb 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(arr) | |
out = [] | |
arr.each do |a| | |
if a.is_a?(Array) | |
out += flatten(a) | |
else | |
out << a | |
end | |
end | |
out | |
end | |
puts flatten([[1, 2, [3]], 4]).inspect | |
# => [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment