-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: array.shift() renamed amount to offset
- Loading branch information
Showing
1 changed file
with
5 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
extension Array { | ||
mutating func shift(_ amount: Int) { | ||
var amount = amount | ||
guard -count...count ~= amount else { return } | ||
if amount < 0 { amount += count } | ||
self = Array(self[amount ..< count] + self[0 ..< amount]) | ||
mutating func shift(_ offset: Int) { | ||
var offset = offset | ||
guard abs(offset) < count else { return } | ||
if offset < 0 { offset += count } | ||
self = Array(self[offset ..< count] + self[0 ..< offset]) | ||
} | ||
} |