reduce complexity of if elseif conditions
问题 I have one function which is having if elseif conditions and the cyclomatic complexity is approaching 5. How do I reduce it? function testFunc() { var step = getModel('step'); if(step === 1) { this.resetTask(); //calling some function this.updateStep(0); return true; } else if(step === 2) { this.initTask; //some other function return true; } else if(step === 3) { this.name === 'add' ? this.add() : this.edit(); return true; } return false; } tried replacing with switch case but it didn't help.