Complete the code to check if two arrays are equal.
arr1 = [1, 2, 3] arr2 = [1, 2, 3] puts arr1 [1] arr2
equal? which checks object identity, not content equality.!= which checks inequality.In Ruby, == checks if two arrays have the same elements in the same order.
Complete the code to find the intersection of two arrays.
arr1 = [1, 2, 3, 4] arr2 = [3, 4, 5, 6] common = arr1 [1] arr2 puts common.inspect
| which returns union, not intersection.- which returns difference.The & operator returns elements common to both arrays (intersection).
Fix the error in the code to get the union of two arrays.
arr1 = [1, 2] arr2 = [2, 3] union = arr1 [1] arr2 puts union.inspect
+ which concatenates but does not remove duplicates.& which returns intersection.The | operator returns the union of two arrays without duplicates.
Fill both blanks to create a hash with array elements as keys and their lengths as values, only for words longer than 3 letters.
words = ["cat", "lion", "tiger", "dog"] lengths = {word[1] for word in words if word[2] 3} puts lengths.inspect
< or == which filter wrong words.=> in the hash comprehension.The code creates a hash where keys are words and values are their lengths, filtering words longer than 3 letters.
Fill all three blanks to create a hash with uppercase words as keys, their lengths as values, only for words longer than 3 letters.
words = ["apple", "bat", "carrot", "dog"] result = {word[1]: [2] for word in words if word.length [3] 3} puts result.inspect
len(word) which is Python syntax, not Ruby.The code creates a hash with uppercase words as keys and their lengths as values, filtering words longer than 3 letters.