Created
May 20, 2024 21:10
-
-
Save zavan/5c1cb824fc834ca0b18d52e12ae9d35f to your computer and use it in GitHub Desktop.
thiago
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dirs = [ | |
'a1', | |
'a2', | |
'a3', | |
'a4', | |
'b1', | |
'b2', | |
'b3', | |
# c missing | |
'd1', | |
'd2', | |
'd3', | |
'd4', | |
'd5', | |
'd6', | |
'd7', | |
# e missing | |
'f1', | |
'f2', | |
'f3', | |
'f4', | |
'f5' | |
] | |
index_table = { | |
'1.1' => 'a1', | |
'1.2' => 'a2', | |
'1.3' => 'a3', | |
'1.4' => 'a4', | |
'2.1' => 'b1', | |
'2.2' => 'b2', | |
'2.3' => 'b3', | |
'3.1' => 'c1', | |
'3.2' => 'c2', | |
'3.3' => 'c3', | |
'3.4' => 'c4', | |
'3.5' => 'c5', | |
'4.1' => 'd1', | |
'4.2' => 'd2', | |
'4.3' => 'd3', | |
'4.4' => 'd4', | |
'4.5' => 'd5', | |
'4.6' => 'd6', | |
'4.7' => 'd7', | |
'5.1' => 'e1', | |
'5.2' => 'e2', | |
'5.3' => 'e3', | |
'6.1' => 'f1', | |
'6.2' => 'f2', | |
'6.3' => 'f3', | |
'6.4' => 'f4', | |
'6.5' => 'f5' | |
} | |
new_index_table = {} | |
last_index = 1 | |
prev_index = nil | |
skipping_index = nil | |
index_table.each do |full_index, dir| | |
index, sub_index = full_index.split('.').map(&:to_i) | |
next if skipping_index == index | |
if sub_index == 1 && !dirs.include?(dir) | |
skipping_index = index | |
next | |
end | |
if prev_index && index != prev_index | |
last_index += 1 | |
end | |
new_full_index = "#{last_index}.#{sub_index}" | |
new_index_table[new_full_index] = dir | |
prev_index = index | |
end | |
puts "Dirs:" | |
pp dirs | |
puts "\nOriginal index table:" | |
pp index_table | |
puts "\nNew index table:" | |
pp new_index_table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment