-
-
Save Amir-A-M/91109840df401e8556605fb12941163e to your computer and use it in GitHub Desktop.
Refactor of confusing code - return early pattern
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
function returnStuff(argument1, argument2) { | |
if (!argument1.isValid()) { | |
throw new Exception(); | |
} | |
if (!argument2.isValid()) { | |
throw new Exception(); | |
} | |
const otherVal1 = doSomeStuff(argument1, argument2); | |
if (!otherVal1.isValid()) { | |
throw new Exception(); | |
} | |
const otherVal2 = doAnotherStuff(otherVal1); | |
if (!otherVal2.isValid()) { | |
throw new Exception(); | |
} | |
return "Stuff"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment