1

I'm having trouble checking if a nested array contains a single array. For example:

a = [[1,2], [3,4]]
a.each do |i|
  b= i.inspect
  puts a.include?(b)
end

The output it false and false. If anyone could help out that would be great.

1
  • Do you want to look for a specific array or just any array? Commented Feb 23, 2017 at 0:50

2 Answers 2

1
a = [[1,2], [3,4]]
a.each do |i|
  # puts i.to_s
  puts a.include?(i)
end

This should do it. inspect is not necessary. This outputs true and true. Uncomment the comment in the code to see the output.

Sign up to request clarification or add additional context in comments.

Comments

0
  1. Flatten the array, Array.flatten
  2. Find the target element, include?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.