0

So lets say I have this array:

var array = ["a","b","c","d"]

Is it possible to move the whole index 2 spaces to the right for example? It should look like this:

var array = ["c","d","a","b"]

What function can I call for this to happen?

Petravd1994
  • 893
  • 1
  • 8
  • 24
  • Various solutions here: http://stackoverflow.com/questions/31554670/shift-swift-array and here: http://stackoverflow.com/questions/33264959/swift-shift-elements-in-array-by-index. – Martin R Sep 28 '16 at 15:00
  • var array = ["a","b","c","d"] func shiftArray(array:[String],byIndex:Int) -> [String]{ let newArray = Array(array.suffixFrom(byIndex)) let newArray2 = Array(array.prefixUpTo(byIndex)) return newArray + newArray2 } shiftArray(array, byIndex: 2) – user3608500 Sep 28 '16 at 15:10

0 Answers0