Hi there,
I have the following problem,
I want to get the pair of given sum by using higher order functions. I am able to do this using iterative approach. Can someone help me to solve the problem using higher order function.
let array = [1,2,3,4]
let givenSum = 5
for i in 0..<array.count {
let j = i + 1
for j in j..<array.count {
if array[i] + array[j] == givenNum {
print("Pair : \(array[i]),\(array[j])")
}
}
}
The output is [2,3]
Any help is appreciated.
Thank you