[Swift]Array Extension #1

Array Extension #1

extension Array {
    mutating func firstToLast(){
        let elm = self.removeFirst()
        self.append(elm)
    }
    mutating func lastToFirst(){
        let elm = self.removeLast()
        self.insert(elm, atIndex: 0)
    }
}

使用

var tmp1:[Int] = [0,1,2,3]
tmp1.firstToLast()
print(tmp1)
tmp1.lastToFirst()
print(tmp1)

出力結果

[1, 2, 3, 0]
[0, 1, 2, 3]