Recap - Reversed Array
Part of the Fundamentals section of Coddy's Swift journey — lesson 67 of 86.
Challenge
EasyYou 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
4Operators Part 1
Arithmetic OperatorsModulo OperatorCompound AssignmentRecap - Simple MathComparison Operators7Basic IO
Print FunctionString InterpolationReadLine InputType ConversionRecap - Till 120Recap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesArgument LabelsRecap - Sigma FunctionRecap - Validation FunctionDefault Values13Iterating Over Sequences
Iterating Over ElementsThe Enumerated MethodIterating Over Strings P1Iterating Over Strings P22Variables
Let vs VarType AnnotationsNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary Operator8Bill Split Calculator
Welcome MessageGetting Input3Optionals
What Are OptionalsUnwrapping With If LetGuard LetNil Coalescing OperatorRecap - Safe Unwrapping9Loops
For-In LoopWhile LoopRepeat-While LoopBreakContinueRecap - FactorialRanges In LoopsNested LoopRecap - Dynamic Input12Arrays Basics
Declaring An ArrayAccessing ElementsModifying ArraysArray MethodsRecap - Product ListRecap - Reversed ArrayTuples