Menu
Coddy logo textTech

Recap - Reversed Array

Part of the Fundamentals section of Coddy's Ruby journey — lesson 63 of 88.

challenge icon

Challenge

Easy

Read a single line of input containing comma-separated integers (e.g., 8,3,5,1,9).

Split the input into an array of integers, then reverse the array manually using a loop. Do not use the built-in reverse method.

Build a new array by iterating through the original array from the last element to the first, adding each element to the new array. Print each element of the reversed array on its own line.

For example, if the input is 8,3,5,1,9, the output should be:

9
1
5
3
8

If the input is 10,20,30, the output should be:

30
20
10

If the input is 7,2,4,6,1,8, the output should be:

8
1
6
4
2
7

If the input is 5, the output should be:

5

Try it yourself

# Read the comma-separated integers
input = gets.chomp
numbers = input.split(",").map(&:to_i)

# TODO: Write your code below
# Create a new array by iterating through the original array
# from the last element to the first (do NOT use the reverse method)
reversed_array = []



# Print each element of the reversed array on its own line
reversed_array.each do |num|
  puts num
end

All lessons in Fundamentals