Recall & Review
beginner
What does the
== operator do when used between two arrays in Ruby?It checks if both arrays have the same elements in the same order.
Click to reveal answer
beginner
How do you find the common elements between two arrays in Ruby?
Use the
& operator to get the intersection of two arrays.Click to reveal answer
beginner
What does the
| operator do with arrays in Ruby?It returns a new array with all unique elements from both arrays combined (union).
Click to reveal answer
intermediate
Explain the difference between
- and ^ (exclusive or) operations on arrays in Ruby.- returns elements from the first array that are not in the second. Ruby does not have a built-in ^ operator for arrays, but you can simulate symmetric difference by combining - and |.Click to reveal answer
intermediate
How can you check if one array is a subset of another in Ruby?
Use
array1 - array2 == [] to check if all elements of array1 are in array2.Click to reveal answer
What will
[1, 2, 3] & [2, 3, 4] return in Ruby?✗ Incorrect
The
& operator returns the intersection, so only elements common to both arrays: 2 and 3.Which operator returns all unique elements from two arrays combined?
✗ Incorrect
The
| operator returns the union of two arrays with unique elements.What does
[1, 2, 3] - [2] return?✗ Incorrect
The
- operator removes elements in the second array from the first, so 2 is removed.How can you check if two arrays have the same elements in the same order?
✗ Incorrect
The
== operator compares arrays element by element in order.Which expression checks if
arr1 is a subset of arr2?✗ Incorrect
If removing all elements of arr2 from arr1 leaves an empty array, arr1 is a subset of arr2.
Describe how to find the intersection, union, and difference of two arrays in Ruby.
Think about set operations and their Ruby symbols.
You got /3 concepts.
Explain how to check if two arrays are equal and how to verify if one array is a subset of another.
Consider comparing elements and removing elements.
You got /2 concepts.