Created
May 21, 2019 19:51
-
-
Save hernandazevedo/7f94a09f394102052c65ce90e9feaaef to your computer and use it in GitHub Desktop.
This file contains 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
func frequency(numbers: [Int]) -> [Int: Int] { | |
var frequencyDictionary: [Int:Int] = [:] | |
for number in numbers { | |
if let existentValue = frequencyDictionary[number] { | |
frequencyDictionary[number] = existentValue + 1 | |
} else { | |
frequencyDictionary[number] = 1 | |
} | |
} | |
return frequencyDictionary | |
} | |
print(frequency(numbers: [1, 3, 1, 1, 2, 7, 3, 5, 8, 5, 4, 9])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment