Last active
April 14, 2016 00:59
-
-
Save carsoncole/ebfe654dfcee357e2ca44adb7cea012d to your computer and use it in GitHub Desktop.
Ruby method that flattens arbitrary number of nested arrays of integers.
This file contains 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 self.flatten(array) | |
array.to_s.gsub(/[\[\]]/,'').split(/\s*,\s*/).map { |x| x.to_i } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment