Skip to content

Instantly share code, notes, and snippets.

@carlosgaldino
Last active September 25, 2015 13:50
Show Gist options
  • Save carlosgaldino/424aa556541a1c6fd9eb to your computer and use it in GitHub Desktop.
Save carlosgaldino/424aa556541a1c6fd9eb to your computer and use it in GitHub Desktop.
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