Created
May 17, 2016 19:40
-
-
Save mfessenden/76a238260082e7bf9ee302b9724f3cb6 to your computer and use it in GitHub Desktop.
Function to return a count of an element in an array
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
import Foundation | |
public extension Array where Element: Equatable { | |
public func frequencyOf(item: Element) -> Int { | |
return filter({ | |
if $0 == item { | |
return true | |
} else { | |
return false | |
} | |
}).count | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment