Find the item in an array with the largest property

Viewed 4704

I have a struct like this

struct Point {
    pub x: i32,
    pub y: i32,
}

impl Point {
    fn new(x: i32, y: i32) -> Self {
        Point { x, y }
    }
}

And an array like this

[Point::new(1, 1), Point::new(4, 2), Point::new(2, 9)];

How do I pull the item with largest point.x from this array?

1 Answers
Related