I'm trying to improve an old React web application for work when i stumble upon this variable:
const condition = (
param !== const1 && param !== const2 && param !== const3 && ...
)
Is there a best practise to improve this very long and condition?
The idiomatic way of performing such check if you're checking running the !==
comparison for all items you should use the Array.every
functional predicate.
It checks that every item matches the condition:
const condition = [value1, value2, value3].every(value => value !== parameter)