Skip to content

Instantly share code, notes, and snippets.

@leodabus
Created January 24, 2017 13:44
Show Gist options
  • Save leodabus/b109b2ca9633c44974399a771690fe1d to your computer and use it in GitHub Desktop.
Save leodabus/b109b2ca9633c44974399a771690fe1d to your computer and use it in GitHub Desktop.
let myArray = [CGPoint(x: 0.1 + 0.2, y: 0), CGPoint(x: 0.3, y: 0), CGPoint(x: 2, y: 2), CGPoint(x: 2, y: 2)]
var counts = [String: Int]()
myArray.forEach { counts[$0.debugDescription] = (counts[$0.debugDescription] ?? 0) + 1 }
if let (value, count) = counts.max(by: {$0.value < $1.value}) {
print("\(value) occurs \(count) times") // "(0.3, 0.0) occurs 2 times\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment