func anyCommonElements<T: Sequence, U: Sequence>(_ lhs: T, _ rhs: U) -> [T.Iterator.Element]
where T.Iterator.Element: Equatable, T.Iterator.Element == U.Iterator.Element {
var list: [T.Iterator.Element] = []
print(type(of: list))
for lhsItem in lhs {
for rhsItem in rhs {
if lhsItem == rhsItem {
list.append(lhsItem)
return list
}
}
}
return list
}
print(anyCommonElements([1, 2, 3], [3]))
print(anyCommonElements(["guo", "teng", "zhao"], ["zhao"]))
网友评论