Voss Voss - 1 year ago 82
Ruby Question

How do I find an array of strings in an array of arrays?

I have an array of numbers I need to match in an array of arrays. How do I match the corresponding array?

Here is the first array:

animals_to_owners = [
["animals to owners"],
["animal id", " owner id"],
["67", " 31"],
["67", " 99"],
["67", " 53"],
["67", " 13"],
["346", " 99"],
["346", " 53"]

And my other array of owner ids:

owner_ids = ["99", "31", "53"]

I've tried
with no luck, I think it's because I'm comparing arrays instead of a single string to an array.

Ultimately I want to find the

Thanks in advance.

ndn ndn
Answer Source
animals_to_owners.select do |_, owner_id|
  owner_ids.include? owner_id.to_s.strip

Note that the weird to_s.strip part is needed due to the spaces in the owner ids.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download