Created
July 19, 2015 05:00
-
-
Save jweinst1/ade3010b17b803da134d to your computer and use it in GitHub Desktop.
Two functions that slice arrays in Swift
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
// Returns a slice of an array that contains characters | |
func StringSlicer(list:Array<Character>, n1:Int, n2:Int) ->Array<Character> { | |
var slicer = n1; var slicedlist = [Character]() | |
while slicer <= n2 { | |
slicedlist.append(list[slicer]) | |
slicer += 1 | |
} | |
return slicedlist | |
} | |
// returns a slice of an array of characters with an increment | |
func StringSlicerIncrement(list:Array<Character>, n1:Int, n2:Int, inc:Int) ->Array<Character> { | |
var slicer = n1; var slicedlist = [Character]() | |
while slicer <= n2 { | |
slicedlist.append(list[slicer]) | |
slicer += inc | |
} | |
return slicedlist | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment