Last active
September 10, 2017 00:21
-
-
Save jakebromberg/988c81a88648e073ff1fe42793a83bb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Sequence where Element: Hashable { | |
func frequencies() -> [Element : Int] { | |
return Dictionary(map { ($0, 1) }, uniquingKeysWith: { $0 + $1 }) | |
} | |
} | |
assert("hello".frequencies() == ["e": 1, "o": 1, "l": 2, "h": 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment