Back to questions
JuniorTheoryCommon
What does the program print?
let scores = [7, 9, 4]
var position = 0
for (i, _) in scores.enumerated() {
position = i
}
print(position, scores.count)2 3
- Expecting
3 3: numbering the elements from1.enumerated()starts at0, so the last number in an array of three elements is2. - Expecting
4 3: thinking the tuple holds the element first and the number second. The number comes first, soigets0,1and2.
- What does the program print if the loop is
for (_, x) in scores.enumerated()withposition = x? - How would you print each element together with its place counted from 1?