Skip to content

Instantly share code, notes, and snippets.

@oliverbarreto
Created June 10, 2015 06:05
Show Gist options
  • Save oliverbarreto/79d136edab10293bf85f to your computer and use it in GitHub Desktop.
Save oliverbarreto/79d136edab10293bf85f to your computer and use it in GitHub Desktop.
New Array from Index Range Swift
//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