Bird
0
0

What does the intersection operation return when applied to two Swift sets?

easy📝 Conceptual Q1 of 15
Swift - Collections
What does the intersection operation return when applied to two Swift sets?
AA new set containing elements only in the second set
BA new set containing all elements from both sets
CA new set containing elements only in the first set
DA new set containing elements common to both sets
Step-by-Step Solution
Solution:
  1. Step 1: Understand the intersection operation

    The intersection of two sets includes only elements that appear in both sets.
  2. Step 2: Apply the definition to Swift sets

    Swift's intersection method returns a new set with elements common to both sets.
  3. Final Answer:

    A new set containing elements common to both sets -> Option D
  4. Quick Check:

    Intersection = Common elements [OK]
Quick Trick: Intersection keeps only shared elements between sets [OK]
Common Mistakes:
  • Confusing intersection with union
  • Thinking it returns elements only from one set
  • Assuming it modifies the original sets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes