1

I need to check if array

a1 = [x, y] 

is presented in array of arrays like

a2 = [ [a, b], [c,d], [e, f] ]

with Ruby 1.9. For example, if x == c and y == d then function must be True. I'v tried

a2.includes? a1 and a1 in a2 but both doesent work.

3
  • 1
    Will a2.any? { |x| x.eql? a1 } do? Commented Apr 18, 2013 at 19:16
  • yep, i just checked and it works too, alongside with include? Commented Apr 18, 2013 at 19:25
  • 1
    I always keep the documentation for Array and Enumerable from Ruby Doc up in my browser at all times when I am coding. It is an invaluable source. Commented Apr 18, 2013 at 19:33

1 Answer 1

5

see you used includes?, which should be include?.

a2 = [ [:a, :b], [:c,:d], [:e,:f] ]
a1 = [:a,:b] 
p a2.include? a1 #=>true

or you could do so as below:

a2 = [ [:a, :b], [:c,:d], [:e,:f] ]
a1 = [:a,:b] 
p a2.one? { |i| i == a1} #=>true
Sign up to request clarification or add additional context in comments.

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.