26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/worldfootball/vacuum.rb', line 26
def self.vacuum( rows, headers: , fixed_headers: )
counter = Array.new( .size, 0 )
rows.each do |row|
row.each_with_index do |col, idx|
counter[idx] += 1 unless col.nil? || col.empty?
end
end
pp counter
= []
indices = []
= []
empty_indices = []
counter.each_with_index do |num, idx|
= [ idx ]
if num > 0 || (num == 0 && .include?( ))
<<
indices << idx
else
<<
empty_indices << idx
end
end
if empty_indices.size > 0
rows = rows.map do |row|
row_vacuumed = []
row.each_with_index do |col, idx|
row_vacuumed << col unless empty_indices.include?( idx )
end
row_vacuumed
end
end
[rows, ]
end
|