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 Swift higher order functions like map, filter etc.
let array = [1,2,3,4,5]
let givenSum = 9
for i in 0..<array.count {
let j = i + 1
for j in j..<array.count {
if array[i] + array[j] == givenSum {
print("Pair : \(array[i]),\(array[j])")
}
}
}
The output is [4,5]
Any help is appreciated. Thank you