在Swift中展平数组数组
发布时间:2020-12-14 02:30:17 所属栏目:百科 来源:网络整理
导读:在Swift中有一个对应的平台在Scala,Xtend,Groovy,Ruby和co? var aofa = [[1,2,3],[4],[5,6,7,8,9]]aofa.flatten() // shall deliver [1,3,4,5,9] 当然我可以使用减少为那,但是那种吸 var flattened = aofa.reduce(Int[]()){ a,i in var b : Int[] = a b
在Swift中有一个对应的平台在Scala,Xtend,Groovy,Ruby和co?
var aofa = [[1,2,3],[4],[5,6,7,8,9]] aofa.flatten() // shall deliver [1,3,4,5,9] 当然我可以使用减少为那,但是那种吸 var flattened = aofa.reduce(Int[]()){ a,i in var b : Int[] = a b.extend(i) return b }
Swift 3.0
减少: let numbers = [[1,9]] let reduced = numbers.reduce([],+) flatMap: let numbers = [[1,9]] let flattened = numbers.flatMap { $0 } 加入: let numbers = [[1,9]] let joined = Array(numbers.joined()) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |