Skip to content

Instantly share code, notes, and snippets.

@gabrielbidula
Created March 1, 2017 10:03
Show Gist options
  • Save gabrielbidula/8f957c822a1f0f855410650b240612e2 to your computer and use it in GitHub Desktop.
Save gabrielbidula/8f957c822a1f0f855410650b240612e2 to your computer and use it in GitHub Desktop.
flatten an array of arbitrarily nested arrays of integers into a flat array of integers
class NiceFlatten
def flatten
to_s
.gsub(/[\[|\]]/, '')
.split(', ')
.map(&:to_i)
end
end
@gabrielbidula
Copy link
Author

flatten using regex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment