Created
May 11, 2016 16:02
-
-
Save mikekavouras/74692c3f03afa779303fd464610feae7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| extension RangeReplaceableCollectionType { | |
| public func slice(start: Int, _ stop: Int = 0, _ step: Int = 1) -> [Generator.Element] { | |
| var _stop = stop | |
| if stop == 0 { | |
| _stop = self.count as! Int | |
| } | |
| var sliced = Array<Generator.Element>() | |
| for (idx, val) in self.enumerate() { | |
| if idx % step != 0 { | |
| continue | |
| } | |
| if idx < start { | |
| continue | |
| } | |
| if idx > _stop { | |
| continue | |
| } | |
| sliced.append(val) | |
| } | |
| return sliced | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment