While exploring algorithms in Swift, couldn\'t find algorithm for array rotation in swift without using funcs shiftLeft / shiftRight.
shiftLeft
shiftRight
C has
// a is the array to be left rotated // d is the number of unit for left rotation
func rotLeft(a: [Int], d: Int) -> [Int] { var a = a for index in 0...(d - 1) { a.append(a[0]) a.remove(at: 0) } return a }
// calling Function
rotLeft(a: [1,2,3,4,5], d: 4)
// OutPut [5, 1, 2, 3, 4]