Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i use xcode btw. swift language, heres a better picture You will implement a higher order function to compare two objects (of int and String
i use xcode btw.
swift language, heres a better picture
You will implement a higher order function to compare two objects (of int and String type) by applying a user-defined condition (via a closure). The function will return true if the condition is met; otherwise, false will be returned. Here is the specification of the function. The function named compareFunction will take three input parameters: obj1: Int? obj2: String? cond: (Int, Int) -> Bool The function has Boolean as its return type. The parameter cond is a closure defining the condition (specified by users) used to compare two int objects. You function needs to do the following. 1. Convert the obj2 object from String into an Int type. Let's assume that obj2 only contain numeric characters so the String.toint) always works. 2. If the input object (obj1 or obj2) is null, initialize it as O before passing to the closure. Please only use the operators ?, ??, and I to accomplish this. 3. Invoke the closure with the objects obtained from step 1 and 2. 4. Return the value which the closure returns from step 3. To test your function, use the code snippet like below. val result = comeare unctionnull,"4") {x,y->Bool in x >=y! In addition to testing the scenarios where obj1 or obj2 might be null, you also need to test all possible conditions to compare two Int objects such as 1. The first int is greater than the second one 2. The first int is less than the second one 3. The first one equals to the second one (CH) - Right: 0" After: WOP Text Opt bring send Forward Backward Selecion Pane Align You will implement a higher order function to compare two objects (of Int and String type) by applying a user-defined condition (via a closure). The function will return true if the condition is met; otherwise, false will be returned. Here is the specification of the function. The function named compareFunction will take three input parameters: obj1: Int? obj2: String? cond: (Int. Int) -> Bool The function has Boolean as its return type. The parameter cond is a closure defining the condition (specified by users) used to compare two Int objects. You function needs to do the following. 1. Convert the obj2 object from String into an Int type. Let's assume that obj2 only contain numeric characters so the String.tolnt() always works. 2. If the input object (obji or obj2) is null, initialize it as O before passing to the closure. Please only use the operators ?., ??, and I to accomplish this. 3. Invoke the closure with the objects obtained from step 1 and 2. 4. Return the value which the closure returns from step 3. To test your function, use the code snippet like below. val result = compareFunction(null, "4") {x,y-> Bool in x >=y} In addition to testing the scenarios where obj1 or obj2 might be null, you also need to test all possible conditions to compare two Int objects such as 1. The first int is greater than the second one 2. The first int is less than the second one 3. The first one equals to the second one Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started