Array

作者: sasky2008 | 来源:发表于2019-02-20 12:15 被阅读3次

    介绍一下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"]
    

    相关文章

      网友评论

          本文标题:Array

          本文链接:https://www.haomeiwen.com/subject/adacyqtx.html