Last active
April 16, 2018 11:03
-
-
Save jbarros35/e4d4d831305e2107997c25e6c4182dd1 to your computer and use it in GitHub Desktop.
Simple count words with dictionary in Swift
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
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