0
0
Rubyprogramming~30 mins

Array comparison and set operations in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Array comparison and set operations
📖 Scenario: You are managing two lists of attendees for two different events. You want to find out who attended both events, who attended only one, and who attended either event.
🎯 Goal: Build a Ruby program that compares two arrays of names using set operations to find common attendees, unique attendees, and all attendees combined.
📋 What You'll Learn
Create two arrays with exact names as given
Create a variable to hold the common attendees
Create a variable to hold attendees unique to the first event
Create a variable to hold all attendees from both events
Print the results exactly as specified
💡 Why This Matters
🌍 Real World
Comparing lists of participants, customers, or items is common in event planning, marketing, and inventory management.
💼 Career
Understanding array comparison and set operations helps in data analysis, filtering, and reporting tasks in many programming jobs.
Progress0 / 4 steps
1
Create two arrays of attendees
Create an array called event1_attendees with these exact names: "Alice", "Bob", "Charlie". Also create an array called event2_attendees with these exact names: "Bob", "Diana", "Edward".
Ruby
Need a hint?

Use square brackets [] to create arrays and separate names with commas.

2
Create variables for set operations
Create a variable called common_attendees that holds the names present in both event1_attendees and event2_attendees. Create a variable called unique_to_event1 that holds names in event1_attendees but not in event2_attendees. Create a variable called all_attendees that holds all unique names from both arrays combined.
Ruby
Need a hint?

Use & for intersection, - for difference, and | for union of arrays.

3
Prepare output strings
Create a variable called common_str that joins the names in common_attendees with commas. Create a variable called unique_str that joins the names in unique_to_event1 with commas. Create a variable called all_str that joins the names in all_attendees with commas.
Ruby
Need a hint?

Use the join method with ", " to combine array elements into a string.

4
Print the results
Print the following lines exactly using puts:
1. "Common attendees: " followed by common_str
2. "Unique to event 1: " followed by unique_str
3. "All attendees: " followed by all_str
Ruby
Need a hint?

Use puts and string interpolation with #{} to print variables inside strings.