Skip to content

Instantly share code, notes, and snippets.

@Maxatma
Created March 9, 2020 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maxatma/63e946b9ab0e6e74f0cf9853373a9456 to your computer and use it in GitHub Desktop.
Save Maxatma/63e946b9ab0e6e74f0cf9853373a9456 to your computer and use it in GitHub Desktop.
Figure out appearance count of each element in array
extension Array where Element: Hashable {
var histogram: [Element: Int] {
return self.reduce(into: [:]) { counts, elem in counts[elem, default: 0] += 1 }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment