Bird
0
0

Given two arrays, how do you combine them into one array without duplicates?

hard📝 Application Q9 of 15
Ruby - Arrays
Given two arrays, how do you combine them into one array without duplicates?
a = [1, 2, 3]
b = [3, 4, 5]
Aa + b
Ba * b
Ca | b
Da & b
Step-by-Step Solution
Solution:
  1. Step 1: Understand array union operator

    The '|' operator combines arrays and removes duplicates.
  2. Step 2: Check other operators

    '+' concatenates but keeps duplicates; '&' finds intersection; '*' repeats arrays.
  3. Final Answer:

    a | b -> Option C
  4. Quick Check:

    Union without duplicates = a | b [OK]
Quick Trick: Use '|' to merge arrays uniquely [OK]
Common Mistakes:
MISTAKES
  • Using + and expecting unique elements
  • Confusing & with union
  • Using * which repeats arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes