2
ary=[ [[0, 0], [0, 1], [0, 2]],
      [[0, 3], [0, 4], [0, 5]],
      [[0, 6], [0, 7], [0, 8]] ]

I am trying to find the index in the "main" array that contains an array with [0, 4] in it, which is 1.

I've been working with the idea like this:

ary.each_index.select{|index| #(return index if [0,4] matches) }

3 Answers 3

6

Try

ary.find_index { |arr| arr.include?([0, 4]) }
Sign up to request clarification or add additional context in comments.

1 Comment

i can't believe i didn't think of this before haha
0

Try to check the following.

Find indices of elements that match a given condition

Get index of array element faster than O(n)

http://apidock.com/ruby/Array/find_index

1 Comment

It's not really an answer if you don't demonstrate how it works. Link-only answers are considered low quality.
0

Try Following.

ary.find_index { |arr| arr.index([0, 4]) }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.