Skip to content

Instantly share code, notes, and snippets.

@zoltankiss
Created February 18, 2017 22:39
Show Gist options
  • Select an option

  • Save zoltankiss/41715dad2f3ac6e3017b319fc9829e0a to your computer and use it in GitHub Desktop.

Select an option

Save zoltankiss/41715dad2f3ac6e3017b319fc9829e0a to your computer and use it in GitHub Desktop.
def flatten(lst)
flattened_lst = []
lst.each do |e|
if e.is_a?(Array)
flattened_lst += flatten(e)
else
flattened_lst << e
end
end
flattened_lst
end
puts flatten([[ 1, 2, [3]], 4]).inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment