Complete the code to print numbers from 1 to 5 using upto method.
1.[1](5) { |i| puts i }
The upto method counts upwards from the starting number to the given number.
Complete the code to print numbers from 5 down to 1 using downto method.
5.[1](1) { |i| puts i }
The downto method counts downwards from the starting number to the given number.
Fix the error in the code to print numbers from 3 up to 7.
3.[1](7) { |num| puts num }
To count upwards from 3 to 7, use upto. Using downto would count downwards and cause no output here.
Fill both blanks to create a hash with keys from 1 to 4 and values counting down from 4 to 1.
result = { [1].[2](1) { |i| [i, 5 - i] } }Start from 4 and count down to 1 using downto. The keys are from 4 down to 1, values calculated as 5 - key.
Fill all three blanks to create a hash with keys from 'a' to 'c' and values from 1 up to 3.
letters = ('a'..'c').to_a numbers = 1.[1](3).to_a result = { [2].zip([3]).to_h }
Use upto to get numbers from 1 to 3. Then zip letters and numbers arrays to create the hash.