Created
February 3, 2018 02:31
-
-
Save xiaoyunyang/434151d48ac8c88d29421b51dbf27bef to your computer and use it in GitHub Desktop.
Hard To Test Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BAD | |
function valIncrementer(val, disabled) { | |
var nextVal = val + 1 | |
function firstStageSetter1() { | |
if(val >= 10) { | |
nextVal = 10 //clip it to high limit value | |
secondStageSetter() | |
} | |
} | |
function firstStageSetter2() { | |
if(val <= 0) { | |
nextVal = 0 //clip it to low limit value | |
secondStageSetter() | |
} | |
} | |
function secondStageSetter() { | |
if(disabled) { | |
nextVal = val | |
} | |
} | |
function run() { | |
firstStageSetter1() | |
firstStageSetter2() | |
} | |
run() | |
return nextVal | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment