Created
April 27, 2015 06:56
-
-
Save shaicoleman/ff0fd24d11f1385d3cce to your computer and use it in GitHub Desktop.
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
module ArrayUtils | |
def self.flatten(a, ret = []) | |
raise ArgumentError, 'parameter must be an array' unless a.is_a?(Array) | |
a.each do |i| | |
if i.is_a?(Array) | |
flatten(i, ret) | |
else | |
ret << i | |
end | |
end | |
ret | |
end | |
end | |
if __FILE__==$0 | |
a = [[1,2,[3]],4,[5,[[6]]]] | |
puts ArrayUtils.flatten(a).inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment