我有2个与zip组合的数组,我希望它们交替(A1索引0、2、3 ...),没有问题。 当数组大小不同时,for循环仅在短数组的持续时间内运行,而忽略了一些较长的数组。有什么提示吗?我尝试了不同的循环,大步前进,但没有喜悦。 即使在更长的数组中,如何获取for循环遍历所有索引?
var a1 = ["one", "three", "five"]
var a2 = ["two", "four"]
var joined = [String]()
for (odd, even) in zip(a1, a2) {
joined.append(odd)
joined.append(even)
}
print(joined) // ["one", "two", "three", "four"] <- the "five" is missing