Complete the code to get the first element of the array.
arr = [10, 20, 30] first_element = arr.[1]
last instead of first.pop which removes the last element.The first method returns the first element of the array.
Complete the code to get the last element of the array.
numbers = [5, 15, 25, 35] last_num = numbers.[1]
pop which removes the last element instead of just accessing it.first which returns the first element.The last method returns the last element of the array without removing it.
Fix the error in the code to access the second element of the array.
items = ['apple', 'banana', 'cherry'] second_item = items[[1]]
Array indexing starts at 0, so the second element is at index 1.
Fill both blanks to create a hash with words as keys and their lengths as values, only for words longer than 3 letters.
words = ['cat', 'lion', 'tiger', 'dog'] lengths = {word => word.[1] for word in words if word.length [2] 3}
size which also works but is less common here.< which filters shorter words.Use length to get the word length and > to check if it's longer than 3.
Fill all three blanks to create a hash with uppercase words as keys, their original words as values, only if the word length is greater than 3.
words = ['ant', 'bear', 'cat', 'dog'] result = {word.[1] => word.[2] for word in words if word.length [3] 3}
length as a key method instead of upcase.< instead of > in the condition.upcase converts the word to uppercase for the key, to_s ensures the value is a string, and > checks length greater than 3.