Skip to content

Instantly share code, notes, and snippets.

@zavan
Created May 21, 2024 13:56
Show Gist options
  • Save zavan/fb9e9929e9bd5caf8dd22e059aad57d2 to your computer and use it in GitHub Desktop.
Save zavan/fb9e9929e9bd5caf8dd22e059aad57d2 to your computer and use it in GitHub Desktop.
dirs = [
"a1",
"a2",
"a3",
"b1",
"b2",
# missing b3
"b4",
"b5",
# missing all c
"d1",
"d2",
# missing all e
"f1",
"f2",
"f3",
# missing f4
"f5",
"f6",
]
groups = [
[
"a1",
"a2",
"a3"
],
[
"b1",
"b2",
"b3",
"b4",
"b5"
],
[
"c1",
"c2"
],
[
"d1",
"d2"
],
[
"e1",
"e2"
],
[
"f1",
"f2",
"f3",
"f4",
"f5",
"f6"
]
]
index_table = {}
index = 1
sub_index = 0
groups.each do |group|
group.each do |dir|
if dirs.include?(dir)
sub_index += 1
index_table["#{index}.#{sub_index}"] = dir
end
end
# At least one dir in the group exists, increment index
if sub_index > 0
index += 1
end
# Reset sub_index
sub_index = 0
end
pp index_table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment