'What do "n" and "i" mean in swift?
I'm teaching myself Swift and am sometimes able to grasp larger concepts while being unclear on details or why they work.
I figured out how to take an array and use a for loop to cycle through every third element and print them in reverse order.
Is "n" is the element's placement in the array? What exactly is "i"?
let numberArray = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"]
func everyOther() {
for (n, i) in numberArray.enumerated().reversed() {
if (n+1).isMultiple(of: 3) {
print(i)
} //if
}// for
}// func
everyOther()
Thank you
Solution 1:[1]
According to https://www.hackingwithswift.com/example-code/arrays/how-to-loop-through-an-array-in-reverse, it is (index, item)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vlad Feinstein |
