I have a boolean expression to evaluate that is pretty long with a lot of different cases:
return (a && b && c) ||
(d && e && f) ||
...
This should return a boolean!
a, b, c, d, e and f being simple equality comparison and being all different. This continues for 12 lines and gives me a Cyclomatic Complexity of 44
I tried to look at the Map object in order to reduce the complexity but did not find a way to do it.
How could I reduce the complexity of such an expression ?
You can not reduce the complexity of the given expression.
A slower approach, but maybe a little more structured, is to group the expressions and evaluate with Array#some
for the outer array and Array#every
for the inner arrays with a short circuit.
return [[a, b, c], [d, e, f]].some(a => a.every(Boolean));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.