Find Last Repeated Character in a string
Code
func getCharCountInString(_ testText:String) {
let dict = testText.reduce([:]) { (d, c) -> Dictionary<Character,Int> in
var d = d
let i = d[c] ?? 0
d[c] = i+1
return d
}
//Accending order
print((dict.sorted{ $0.key < $1.key }).map{ "\($0)\($1)"}.joined())
//Without Accending order
print((dict.map{ "\($0)\($1)"}).joined())
}