Skip to content

Instantly share code, notes, and snippets.

@mfessenden
Created May 17, 2016 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfessenden/76a238260082e7bf9ee302b9724f3cb6 to your computer and use it in GitHub Desktop.
Save mfessenden/76a238260082e7bf9ee302b9724f3cb6 to your computer and use it in GitHub Desktop.
Function to return a count of an element in an array
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