Skip to content

Instantly share code, notes, and snippets.

@jakebromberg
Last active September 10, 2017 00:21
Show Gist options
  • Save jakebromberg/988c81a88648e073ff1fe42793a83bb3 to your computer and use it in GitHub Desktop.
Save jakebromberg/988c81a88648e073ff1fe42793a83bb3 to your computer and use it in GitHub Desktop.
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