> For the complete documentation index, see [llms.txt](https://sagar-r-kothari.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sagar-r-kothari.gitbook.io/blog/_posts/2020-02-06-array-rotation.md).

# 2020-02-06-Array-Rotation

```swift
import Foundation

var array = [1,2,3,4,5,6,7,8,9]

extension Array {
    mutating func rotate(count: Int) {
        for _ in 0..<count {
            guard let firstElement = first else { return }
            remove(at: 0)
            append(firstElement)
        }
    }
}

array.rotate(count: 5)
```
