I've been looking for the ideal coding patterns used to score well in a Cyclomatic Complexity.
Of course, code will be subject to change according to what is being developed but regardless the objective of the application there will always be the fundamentals: conditions, returns etc.
For an instance, what is considered less complex from the following two examples:
//Example A
const isDogBarking = false;
if (isDogBarking) {
return 'Yes, Dog is barking';
}
return 'No, Dog is not barking';
Vs
//Example B
const isDogBarking = false;
return isDogBarking ? 'Yes, Dog is barking' : 'No, Dog is not barking';
In my opinion Example A has two returns and example B has only one. Hence, the latter would be better.
I strive to improve the quality of my code but unfortunately I cannot find the most effective coding pattern in Javascript
EDIT - The following questions has been included in this question.
What does it take to add complexity in code?
Having a function existing (by returning or breaking) at the earliest possible or to return only once at the end?
In an if condition, to check the true value first and add the negative code in the else block? does it make a difference whether to check positivity first rather than the negativity ?
To have a nested if conditions (looking like an arrow) or to create an if condition for each possible outcome instead?
Switch statement does give a better reading than a never-ending if condition. But does it make the code less complex?
These are simple questions which I was hoping to find when it comes to learning about Cyclomatic Complexity.