Drawing from Correct way to find max in an Array in Swift, I am attempting to find the leftmost position in Swift array using reduce
. I would have thought that this would work:
var a = [CGPoint(x:1,y:1),CGPoint(x:2,y:2),CGPoint(x:0,y:0)]
var leftMost = a.reduce(CGPoint(x:CGFloat.max,y:CGFloat.max)) {min($0.x,$1.x)}
However, I get this error:
`Type 'CGPoint' does not conform to protocol 'Comparable'
Of course, I'm not comparing a CGPoint, I'm comparing the point .x
, whic should be a CGFloat
.
Ideas?