Last active
February 3, 2018 04:57
-
-
Save xiaoyunyang/dfc02f5625d83eaf8a72bc80a121cc7c to your computer and use it in GitHub Desktop.
More Testable 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
// BETTER - more testable | |
const incrementedVal = (val) => val + 1 | |
function substituteVal(val, low, high) { | |
if(val >= high) return high | |
else if(val <= low) return low | |
else return val | |
} | |
function shouldIncrement(val, disabled) { | |
return val >= 0 && val < 10 && !disabled | |
} | |
function valIncrementer(val, disabled) { | |
if( shouldIncrement(val, disabled) ) { | |
return incrementedVal(val) | |
} | |
return substituteVal(val, 0, 10) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment