extension of sequence

extension Sequence where Element: Hashable { //extension on sequence where element conforms to hashable protocol
    var frequencies: [Element: Int] { //dictionary of key element and value int
        return Dictionary(self.map{ ($0, 1)}, uniquingKeysWith: +) //creates new dictionary for key-value pairs in sequence and increments the value for duplicate keys

Looking at line 3 here, is a new dictionary created and the key-value pairs are mapped to a value of 1 for every key-value pair as the keys are incremented?

Powered by WPeMatico


You may also like...

Comments are closed.