Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Swift - iOS Xcode 9.4 Write a function that: - takes in an array of integers and separates each element ofthe array into odd and

Swift - iOS Xcode 9.4

Write a function that:

- takes in an array of integers and separates each element ofthe array into odd and even numbers

- then splits the array into lists that are sorted in DESCENDINGorder (largest first, smallest last)

- finally, your function should return the sorted evens and oddsas a tuple

- Each element in the array COULD be nil. So you will have tofigure out how to represent that in the parameter's type.

- If an element in the array is nil, do nothing with it.

- Don't forget edge cases like an empty data or all nilvalues.

Notes:

- Research how to return multiple values (as a named tuple) fromSwift functions

- DO NOT manually sort the integers; find a better way usingSwift's libraries!

- Your function MUST work with the commented out function callsbelow!

//let sortedNumbers = sortedEvenOdd(numbers: [0, 9, 3, nil, 8,15, 11, 2, 20, nil])

//print(sortedNumbers.evens) // [20, 8, 2, 0]

//print(sortedNumbers.odds) // [15, 11, 9, 3]

Step by Step Solution

3.40 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

Here is the solution for the above question func sortedEvenOddnumbers Int evens Int odds Int Create ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Java Programs A Back To Basics Approach

Authors: Stuart Reges, Marty Stepp

5th Edition

013547194X, 978-0135471944

Students also viewed these Electrical Engineering questions

Question

Middleware functions stop once a response has been sent back.

Answered: 1 week ago