gpt4 book ai didi

arrays - 如何将 "merge"两个数组放在一起? (逐项连接字符串)

转载 作者:搜寻专家 更新时间:2023-10-31 22:00:36 24 4
gpt4 key购买 nike

假设我有两个 NSString 数组:

var firstName = ["Jack", "Sarah", "John"]
var lastName = ["Smith", "Brown", "Doe"]

我怎样才能将它们组合成一个数组,看起来像,

var contacts = ["Jack Smith", "Sarah Brown", "John Doe"]

最佳答案

您可以使用 Zip2(它从给定的数组) + map():

let firstName = ["Jack", "Sarah", "John"]
let lastName = ["Smith", "Brown", "Doe"]

let contacts = map(Zip2(firstName, lastName)) { $0 + " " + $1 }

关于arrays - 如何将 "merge"两个数组放在一起? (逐项连接字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29218980/

24 4 0