Let's take for example I have this array:
let dates = ["01/02/16", "02/02/16", "03/02/16", "01/02/16", "02/02/16"]
What I like to do is store each String date in a dictionary as the key, and for each key that repeats, I like to store the index of it as an array, and associate it with the duplicate key.
For example, 01/02/16 occurs at index 0 and 3. 02/02/16 occurs at index 1 and 4.
I like to have a dictionary that is something like this:
[ "01/02/16": [0, 3], "02/02/16": [2, 4], "03/02/16": [1] ]
I know how to keep track of how many duplicate entries there are like this:
let dates = ["01/02/16", "01/02/16", "02/02/16", "03/02/16"]
var dateCounts:[String:Int] = [:]
for date in dates
{
dateCounts[date] = (dateCounts[date] ?? 0) + 1
}
for (key, value) in dateCounts
{
print("\(key) occurs \(value) time/s")
}
However, I'm not sure how to keep track of the duplicate indices?