通过给 Sequence 添加 extension 去检测 Element 的频率
let result = "hello".frequencies.filter { $0.value > 1 }
print(result) // ["l": 2]
import Foundation
extension Sequence where Element: Hashable {
var frequencies: [Element: Int] {
return Dictionary(lazy.map { ($0: 1) }, uniquingKeysWith: +)
}
}