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