Complete the code to create an empty array.
arr = [1]In Ruby, square brackets [] create an empty array.
Complete the code to create an array with numbers 1 to 5 using a range.
arr = (1..[1]).to_a
The range 1..5 includes numbers from 1 to 5. Calling to_a converts it to an array.
Fix the error in the code to create an array with 3 elements, all set to 0.
arr = Array.new([1], 0)
Array.new(3, 0) creates an array with 3 elements, each set to 0.
Fill both blanks to create an array of 4 elements, each initialized to its index multiplied by 2.
arr = Array.new([1]) { |[2]| [2] * 2 }
Array.new(4) { |i| i * 2 } creates an array [0, 2, 4, 6].
Fill all three blanks to create an array of 3 elements, each a string 'item' followed by its index.
arr = Array.new([1]) { |[2]| "[3]#{ [2] }" }
This code creates ["item0", "item1", "item2"] by combining the string 'item' with the index.
