介绍一下Array的几个方法
lexicographicallyPrecedes -> Bool
let a = [1,2,3]
let b = [1,2,3,1]
a.lexicographicallyPrecedes(b) // true 1.2.3 < 1.2.3.1
partition -> Int
var fibonacci = [1, 1, 0, 2, 3, 5]
let privot = fibonacci.partition(by: { $0 < 1 })
// 利用条件排序后切割数组 获取满足的一部分
fibonacci[0 ..< privot] // [1,1,2,3,5]
fibonacci[privot ..< fibonacci.endIndex] //[0]
let m = ["A", "N"]
let c = ["a", "n"]
let dd = m.flatMap { (element) -> [String] in
c.map { element + $0 }
}
print(dd)
// ["Aa", "An", "Na", "Nn"]
网友评论