Commit f3fb43c7 authored by Christopher Aue's avatar Christopher Aue

Reimplemented Array#flatten with #flatten!

parent ccd55542
......@@ -169,15 +169,9 @@ class Array
# a.flatten(1) #=> [1, 2, 3, [4, 5]]
#
def flatten(depth=nil)
ar = []
self.each do |e|
if e.is_a?(Array) && (depth.nil? || depth > 0)
ar += e.flatten(depth.nil? ? nil : depth - 1)
else
ar << e
end
end
ar
res = dup
res.flatten! depth
res
end
##
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment