ary=[ [[0, 0], [0, 1], [0, 2]],
[[0, 3], [0, 4], [0, 5]],
[[0, 6], [0, 7], [0, 8]] ]
我正在尝试在“main”数组中找到包含[0, 4]
的数组的索引,该数组为1
。
我一直在研究这样的想法:
ary.each_index.select{|index| #(return index if [0,4] matches) }
答案 0 :(得分:6)
尝试
ary.find_index { |arr| arr.include?([0, 4]) }
答案 1 :(得分:0)
尝试检查以下内容。
Find indices of elements that match a given condition
答案 2 :(得分:0)
尝试以下。
ary.find_index { |arr| arr.index([0, 4]) }