Bird
0
0

You have two arrays representing user IDs: active_users = [1, 2, 3, 4, 5] and premium_users = [3, 4, 6, 7]. How do you find users who are active but not premium?

hard📝 Application Q8 of 15
Ruby - Arrays

You have two arrays representing user IDs: active_users = [1, 2, 3, 4, 5] and premium_users = [3, 4, 6, 7]. How do you find users who are active but not premium?

Aactive_users & premium_users
Bactive_users - premium_users
Cactive_users | premium_users
Dpremium_users - active_users
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem

    We want users in active_users who are NOT in premium_users.
  2. Step 2: Use array difference

    The - operator removes elements of the second array from the first, giving non-premium active users.
  3. Final Answer:

    Use active_users - premium_users to find active but not premium users -> Option B
  4. Quick Check:

    Find difference with - operator [OK]
Quick Trick: Subtract premium from active to find non-premium active users [OK]
Common Mistakes:
  • Using & for difference
  • Using | for difference
  • Subtracting active from premium

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes