Is a shorter statement possible in this case?
Andrey Zherikov
andrey.zherikov at gmail.com
Mon Nov 6 04:05:30 UTC 2023
On Sunday, 5 November 2023 at 18:36:40 UTC, Ctn-Dev wrote:
> Is there a more concise way of getting the same result?
Try this:
```d
switch(range.map!(_ => (_== "Two" ? 2 : _=="One" ? 1 :
0)).fold!((a,b) => a | b)(0)) {
case 3: writeln("both"); break;
case 2: writein("only two"); break;
case 1: writeln("only one"); break;
default: writeln("none"); break;
}
```
Where `range` is input array.
More information about the Digitalmars-d-learn
mailing list