【发布时间】:2015-05-14 01:39:44
【问题描述】:
假设我有这个字符串数组:
let Vehicles = ["Aeroplane", "Bicycle", "CarVehicle", "Lorry", "Motorbike", "Scooter", "Ship", "Train"]
我想要的是这样的结果:
let resultArray = [["Aeroplane", "Bicycle", "CarVehicle", "Lorry"], ["Motorbike", "Scooter", "Ship", "Train"]]
我知道我可以通过 for 做到这一点,但我想在 Swift 中使用高阶函数。我的意思是像 map、reduce、filter 这样的函数。我认为这样做是可能的,而且可能会更好。谁能帮我这个?谢谢
【问题讨论】:
-
参见my answer 一个非常相似的问题,该问题提供多达 5 种不同的方法来解决您的问题。