ruby - flatten-array (cleanup)
This commit is contained in:
parent
0c62b03ef1
commit
1b675cccc5
@ -1,12 +1,8 @@
|
|||||||
class FlattenArray
|
class FlattenArray
|
||||||
def self.flatten(array)
|
def self.flatten(array, result = [])
|
||||||
recursive_flatten(array)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.recursive_flatten(array, result = [])
|
|
||||||
array.each do |a|
|
array.each do |a|
|
||||||
if a.is_a? Array
|
if a.is_a? Array
|
||||||
recursive_flatten(a, result)
|
flatten(a, result)
|
||||||
else
|
else
|
||||||
result << a unless a.nil?
|
result << a unless a.nil?
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user