I’ve been working on this challenge for days… with maybe some success, but I can not figure out how to automatically switch if you input Int vs. Strings. I’d love to see a real fix Comments show one try.
func findAll<T: Equatable, U: Equatable>(_ A1: [T], _ B1: (U)) -> [Int] {
var result = [Int]()
var counter = 0
let tB = type(of: B1)
print(" tB = \(tB)")
for _ in A1 {
// if tB as! String == “String” {
// print(“It’s a String”)
// let lhs:String = B1 as! String
// let rhs:String = A1[counter] as! String
// } else {
// print(“it’s not a String”)
let lhs:Int = B1 as! Int
let rhs:Int = A1[counter] as! Int
// }
if (lhs == rhs) {
result.append(counter)
print("match found")
} else {
print("not matched")
}
// print("A1 counter = \(A1[counter]) " )
// print("result = \(result)")
counter += 1
}
print(" \nMatches at these indicies: \(result)")
return result
}
let answer = findAll([5,3,7,3,9], 3)
//let answer = findAll([“fish”,“turkey”, “duck” ,“turtle” ,“duck”], “duck”)
//findAll([“fish”,“turkey”, “duck” ,“turtle” ,“duck”], “duck”)