Skip to content

Instantly share code, notes, and snippets.

@shaicoleman
Created April 27, 2015 06:56
Show Gist options
  • Save shaicoleman/ff0fd24d11f1385d3cce to your computer and use it in GitHub Desktop.
Save shaicoleman/ff0fd24d11f1385d3cce to your computer and use it in GitHub Desktop.
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