Is a shorter statement possible in this case?

Ctn-Dev wanderingMesos at protonmail.com
Sun Nov 5 18:36:40 UTC 2023


I wrote this earlier:

```
import std.stdio;
import std.algorithm.searching;

string[] numeric_traits_1 = [];
string[] numeric_traits_2 = ["Two"];
string[] numeric_traits_3 = ["One"];
string[] numeric_traits_4 = ["One", "Two"];

void main() {

     void numeric_traits_contains(string[] numeric) {
         if(numeric.canFind("One") & numeric.canFind("Two")) {
             writeln("Array contains 'One' and 'Two'.");
         } else if(numeric.canFind("One", "Two")) {
             writeln("Array contains 'One' or 'Two'.");
         } else {
             writeln("Array contains neither 'One' nor 'Two'");
         }
     }

     numeric_traits_contains(numeric_traits_1);
     numeric_traits_contains(numeric_traits_2);
     numeric_traits_contains(numeric_traits_3);
     numeric_traits_contains(numeric_traits_4);
}
```

`if` runs when both "One" and "Two" are in the given array as 
intended, but its conditional statement looks verbose. Is there a 
more concise way of getting the same result?


More information about the Digitalmars-d-learn mailing list