Created
June 10, 2015 06:05
-
-
Save oliverbarreto/79d136edab10293bf85f to your computer and use it in GitHub Desktop.
New Array from Index Range Swift
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
//Take the first n elements from an array: | |
func aFunction(numbers: Array<Int>, position: Int) -> Array<Int> { | |
var newNumbers = Array(numbers[0..<position]) | |
return newNumbers | |
} | |
// test | |
aFunction([1, 2, 3], 2) // returns [1, 2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment