Created
October 25, 2018 06:57
-
-
Save peterkos/59bfa9cf1613dec9ff7b7f7a20dc7736 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
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