using std.algorithm to find intersection of DateTime[][] arg
Laeeth Isharc via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Sep 11 06:05:57 PDT 2015
On Thursday, 10 September 2015 at 11:58:10 UTC, deed wrote:
> On Wednesday, 9 September 2015 at 20:28:35 UTC, Laeeth Isharc
> wrote:
>> I have a DateTime[][] arg ...
>> I would like to find the intersection of the dates.
>
> A suggestion:
>
> auto minLength = arg.map!(a => a.length).reduce!min;
> auto minIdx = arg.map!(a =>
> a.length).countUntil(minLength);
> auto intersection = arg[minIdx].filter!(e =>
> chain(arg[0..minIdx], arg[minIdx..$]).all!(a =>
> a.assumeSorted.contains(e)));
>
> reduce with setIntersection seems the most straightforward, but
> needs array AFAIK, i.e.:
>
> auto intersection =
> //reduce!((r, x) => setIntersection(r, x))(arg); //
> doesn't work
> reduce!((r, x) => setIntersection(r, x).array)(arg);// does,
> but with array
Thank you for this - exactly what I was looking for - and for the
other answer.
Laeeth.
More information about the Digitalmars-d-learn
mailing list