Skip to content

Instantly share code, notes, and snippets.

@peterkos
Created October 25, 2018 06:57
Show Gist options
  • Save peterkos/59bfa9cf1613dec9ff7b7f7a20dc7736 to your computer and use it in GitHub Desktop.
Save peterkos/59bfa9cf1613dec9ff7b7f7a20dc7736 to your computer and use it in GitHub Desktop.
import UIKit
let array = [5, 16, 67, 2, 9]
// "Manual" way
for index in stride(from: 0, to: array.count, by: 2) {
print(array[index])
}
// Prints 5, 67, 9
// Slightly fancier
let newArray = array.filter({ $0.distance(to: array.count) % 2 == 0 })
print("New array: \(newArray)")
// Prints 5, 67, 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment