Honestly, I think the way you wrote it clearly shows what you want to do.
You can make it more compact using the methods shown in other answers, but I find how you wrote it is easier to understand at first glance than other IMOs.
It all depends on what you want. Method || probably more effective, but your reader is quite readable.
Wrapping this in a function will be fine.
source share