Re: Is a shorter statement possible in this case?

2023-11-06 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 5 November 2023 at 18:36:40 UTC, Ctn-Dev wrote: I wrote this earlier: [...] `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? If sorting the arrays is an

Re: Is a shorter statement possible in this case?

2023-11-05 Thread user1234 via Digitalmars-d-learn
On Sunday, 5 November 2023 at 18:36:40 UTC, Ctn-Dev wrote: I wrote this earlier: [...] 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? Yes, assuming you accept to drop

Re: Is a shorter statement possible in this case?

2023-11-05 Thread Andrey Zherikov via Digitalmars-d-learn
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

Is a shorter statement possible in this case?

2023-11-05 Thread Ctn-Dev via Digitalmars-d-learn
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) {