# 如何分配ID以标识重复的数组元素？

``````duplicates =
["link_B", [247936, 672212, 248156, 671720]],    # Same coordinates as previous line
["link_C", [247936, 672212, 248156, 671720]],    # Same coordinates as previous line
["link_E", [247471, 671767, 247567, 671846]],    # Same coordinates as previous line
["link_G", [247567, 671846, 247775, 671680]]]    # Same coordinates as previous line
``````

``````duplicates =
[["1", "link_A", [247936, 672212, 248156, 671720]],
["1", "link_B", [247936, 672212, 248156, 671720]],    # Same coordinates as previous line
["1", "link_C", [247936, 672212, 248156, 671720]],    # Same coordinates as previous line
["2", "link_D", [247471, 671767, 247567, 671846]],
["2", "link_E", [247471, 671767, 247567, 671846]],    # Same coordinates as previous line
["3", "link_F", [247567, 671846, 247775, 671680]],
["3", "link_G", [247567, 671846, 247775, 671680]]]    # Same coordinates as previous line
``````

1. 不变异“重复项” //不按顺序假设
2. 不变异“重复项” //按顺序假定重复项
3. 突变“重复项” //不按顺序假设

``````duplicates = segment_store.group_by{|i| i[1]}.select{|k,v| v.length > 1}.values.flatten(1)
``````

``````enum = 1.step
duplicates.each_with_object({}).map do |(string, array), cache|
[cache[array] ||= enum.next, string, array]
end
``````

0条评论