我有6种不同颜色的数组:
var colorList: [String] = ["blue", "green", "purple", "red", "yellow", "orange"]
我正在尝试创建一个函数,将每个元素向右移动一个,如下所示:
["orange", "blue", "green", "purple", "red", "yellow"]
我该怎么做?
答案 0 :(得分:5)
$(labArr[i].selector).find(".panel-default:not(.panel-body, .panel-heading)").find("p").remove();
或作为Array
的扩展colorList.insert(colorList.popLast()!, atIndex: 0)
extension Array {
mutating func shiftRight() {
if let obj = self.popLast(){
self.insert(obj, atIndex: 0)
}
}
}
结果
var colorList: [String] = ["blue", "green", "purple", "red", "yellow", "orange"]
colorList.shiftRight()
print(colorList)