0

I'm trying to implement pattern matching, comparing an array of hashes vs. another array of hashes. Each array can have 1 to 3 hashes.

If I have these arrays:

a = [{"name" => "Size", "value" => "S"}, {"name" => "Color", "value" => "Red"}]

b = [{"name" => "Size", "value" => "S"}, {"name" => "Material", "value" => "Cotton"}, {"name" => "Color", "value" => "Red"}]

or another scenario:

a = [{"name" => "Size", "value" => "S"}, {"name" => "Color", "value" => "Red"}, {"name" => "Material", "value" => "Cotton"}]

b = [{"name" => "Size", "value" => "S"}, {"name" => "Material", "value" => "Cotton"}, {"name" => "Color", "value" => "Red"}]

How do I use case/in to compare them so it returns true? Do I need to convert the hash into be keyed by symbols first?

1
  • I assume you want to get true when 2 arrays have same values right? Are you looking for something like this: ((a-b) + (b-a)).empty?
    – darkinsyde
    Commented Jul 31, 2024 at 6:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.