Skip to content

Instantly share code, notes, and snippets.

@jbarros35
Last active April 16, 2018 11:03
Show Gist options
  • Save jbarros35/e4d4d831305e2107997c25e6c4182dd1 to your computer and use it in GitHub Desktop.
Save jbarros35/e4d4d831305e2107997c25e6c4182dd1 to your computer and use it in GitHub Desktop.
Simple count words with dictionary in Swift
var dictionary = [String: Int]()
var counts = "all for all fun fun funny".components(separatedBy:" ").map({
var counter = dictionary[$0] ?? 0
dictionary[$0] = counter + 1
})
print(dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment