Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import Cocoa
// MARK: Goal- Find the number of times any item appears in array
var tayLyrics = "Nice to meet you, where you been? I could show you incredible things Magic, madness, heaven, sin Saw you there and I thought Oh my God, look at that face You look like my next mistake Love’s a game, want to play? New money, suit & tie"
var stringArray = tayLyrics.componentsSeparatedByString(" ")
var intArray = [1,4,5,2,6,6,6]
// This method simply means
func findItemCountForArray<T:Hashable>(arr:[T]) -> [T: Int] {
// 1
var countDict = [T: Int]()
for key in arr {
// 2
if countDict[key] == nil {
countDict[key] = 0
// 3
countDict[key]! += 1
return countDict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment