Menu
Coddy logo textTech

Recap - Reversed Array

Part of the Fundamentals section of Coddy's Swift journey — lesson 67 of 86.

challenge icon

Challenge

Easy

You will receive a line of input containing comma-separated integers (e.g., 1,2,3,4,5).

Reverse the array manually using a loop—do not use the built-in reversed() method.

Build a new array by iterating through the original array from the last index to the first, appending each element to your result array.

Print the reversed array.

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

[40, 30, 20, 10]

Try it yourself

// Read input and convert to array of integers
let input = readLine()!
let numbers = input.split(separator: ",").map { Int($0)! }

// TODO: Write your code below
// Reverse the array manually using a loop (do not use reversed())
// Build a new array by iterating from the last index to the first

var reversedArray: [Int] = []

// Your loop goes here


// Output the result
print(reversedArray)

All lessons in Fundamentals