Question: ( 2 0 pts ) A swift function can take another function as one of its arguments. Create a swift function isOddNum ( number: Int

(20 pts) A swift function can take another function as one of its arguments. Create a swift function isOddNum(number: Int)-> Bool, which has an input parameter number and returns a Boolean value. If the input number is odd, it returns true; otherwise, it returns false.
Create another function hasAnyOddNumber, which uses an array of integers as an input parameter, and an input function. The above function isOddNum will be used as the argument of the input function parameter. The function hasAnyOddNumber returns true if an odd number exists in the input array. Otherwise, it returns false.
Test the created functions using the following code:
var numbers1=[20,14,6,12]
var result1= hasAnyOddNumber (numArray: numbers1, condition: isOddNum)
print("The first array testing result is:
var result2= hasAnyOddNumber(numArray: numbers2, condition: isOddNum)
print("The second array testing result is: (result2)")
The following is the expected result:
IT 358 Assignment 01: Q4(Your Name)
The first array testing result is: false
The second array testing result is: true
 (20 pts) A swift function can take another function as one

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!