So far I have this:
func myFunc(arr: [Int]) {
var arr2 = arr
var count = 1
for i in 0..<arr.count {
for j in i + 1..<arr2.count {
if arr2[i] == arr2[j] {
count += 1
arr2.remove(at: j)
}
}
print("\(arr2[i])-\(count)")
count = 1
}
}
myFunc(arr: [5,6,5])
I want it to print (5 - 2) (6 - 1) I am getting a fatal error every time I want to remove the repeated element, can you explain why and how to solve this problem?