I have some array of Tuples with definition like this:
[(description: [String], criterion: Int, relative: Double, average: Int, type: String, group: Int)] and sorted by decrease of .criterion.
I need to add .group member to each Touple in this array based on matching values of .criterion.
Value of .group is 1...n increasing by 1. If several Tuples have the same value of .criterion, then they will have the same value of .group.
If Tuple have unique .criterion, then it only one will have unique .group value.
I'm trying to do this in code below:
func appendingGroup(_ input: [(description: [String], criterion: Int, relative: Double, average: Int, type: String, group: Int)]) -> [(description: [String], criterion: Int, relative: Double, average: Int, type: String, group: Int)] {
var output: [(description: [String], criterion: Int, relative: Double, average: Int, type: String, group: Int)] = []
var index = 1
while index < input.count - 1 {
if input[index].criterion != input[index + 1].criterion && input[index].criterion != input[index - 1].criterion {
print(index)
output[index].group = index
}
index += 1
}
return output}
This is based on @Nicolai Henriksen question Swift: loop over array elements and access previous and next elements
But I have [] in my output.
What I'm doing wrong?