Created
March 1, 2017 10:03
-
-
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
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
class NiceFlatten | |
def flatten | |
to_s | |
.gsub(/[\[|\]]/, '') | |
.split(', ') | |
.map(&:to_i) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
flatten using regex