How to copy end of the Array in swift?

后端 未结 6 1738
感动是毒
感动是毒 2020-11-30 15:20

There must be some really elegant way of copying end of the Array using Swift starting from some index, but I just could not find it, so I ended with this:

f         


        
6条回答
  •  日久生厌
    2020-11-30 15:55

    You could use filter

    func getEndOfArray( arr : [Int], fromIndex : Int? = 0) -> [Int] {
        let filteredArray = arr.filter({$0 <= fromIndex})
    
        return filteredArray
    }
    

    took the liberty of changing to [Int] for the sake of this example.

提交回复
热议问题