Any path to the chain == and || operands

I have a situation where I have to do a check as follows:

if foo == a || foo == b || foo == c {
  //do stuff
}

is there any way to associate these operands with something smaller than the IDK foo == a||b||c

+4
source share
1 answer

Try the following:

if [a, b, c].contains(foo) {
   //do stuff
}
+7
source

All Articles