how to get min x y and max x y of an array of points using fold
Thomas
thombetteridge at gmail.com
Wed May 21 02:25:47 UTC 2025
struct Point
{
double x, y;
}
import std.algorithm : min, max;
auto min_x = double.max;
auto max_x = -double.max;
auto min_y = double.max;
auto max_y = -double.max;
foreach (const ref p; points) // fold
{
min_x = min(min_x, p.x);
max_x = max(max_x, p.x);
min_y = min(min_y, p.y);
max_y = max(max_y, p.y);
}
Hello,
I am trying to find the min and max values from an array of
points, I want to replace this with the std.algorithm fold, but I
can't quite figure out the syntax for doing it?
More information about the Digitalmars-d-learn
mailing list