On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote:
Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way?

I made it this way, I consider it elegant. I don't know if others will like it.
Here it is:
import std.stdio : writeln;
import std.algorithm.searching;
import std.algorithm.sorting;

void main()
{
    int[] a = [3, 9, 1, 4, 7, 6, 5, 8, 2];
    int[] b = [5, 4, 6];
    //first we sort both of them
    sort(a);
    sort(b);
    //now we check them using slices
writeln(b == a[a.countUntil(b[0]) .. a.countUntil(b[$ - 1]) + 1]);
}

It should output `true`

Reply via email to