Complete the code to remove nil values from the array.
array = [1, nil, 2, nil, 3] clean_array = array.[1]
The compact method removes all nil values from an array.
Complete the code to remove nil values from the hash values.
hash = {a: 1, b: nil, c: 3, d: nil}
clean_hash = hash.select { |_, v| v [1] }The block keeps pairs where the value is not nil, effectively removing nil values.
Fix the error in the code to remove nil values from the array.
numbers = [5, nil, 7, nil, 9] numbers = numbers.[1]()
The method compact returns a new array without nils. compact! modifies in place but requires parentheses.
Complete the code to create a hash with word lengths, excluding nil words.
words = ["apple", nil, "pear", nil, "plum"] lengths = {word => 0: word.{BLANK_2}}
The hash uses word => 0 syntax and size method to get word length.
Fill all three blanks to create a hash of uppercase words and their lengths, excluding nils.
words = ["dog", nil, "cat", "bird"] result = { [1]: [2] for word in words if word [3] nil }
The key is the uppercase word, the value is its length, and the condition excludes nils.
