Created
January 24, 2017 13:44
-
-
Save leodabus/b109b2ca9633c44974399a771690fe1d 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
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