Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@xiaoyunyang
Created February 3, 2018 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaoyunyang/434151d48ac8c88d29421b51dbf27bef to your computer and use it in GitHub Desktop.
Save xiaoyunyang/434151d48ac8c88d29421b51dbf27bef to your computer and use it in GitHub Desktop.
Hard To Test Code
// 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