Bird
0
0

Which operator in Ruby returns the common elements between two arrays?[1, 2, 3] ? [2, 3, 4]

easy📝 Conceptual Q11 of 15
Ruby - Arrays

Which operator in Ruby returns the common elements between two arrays?

[1, 2, 3] ? [2, 3, 4]
A& (intersection)
B| (union)
C- (difference)
D== (equality)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the operators

    The & operator returns elements common to both arrays.
  2. Step 2: Apply to example arrays

    For arrays [1, 2, 3] and [2, 3, 4], common elements are 2 and 3.
  3. Final Answer:

    & (intersection) -> Option A
  4. Quick Check:

    Common elements = & [OK]
Quick Trick: Use & for common items between arrays [OK]
Common Mistakes:
  • Confusing union (|) with intersection (&)
  • Using - for common elements
  • Thinking == compares elements regardless of order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes