Created
October 9, 2019 17:03
-
-
Save NyaGarcia/4f93b44dcee6980d113413c2efc681a6 to your computer and use it in GitHub Desktop.
Extracting a conditional to a function
This file contains hidden or 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 isGameLost() { | |
return ( | |
remaining === 0 || | |
(remaining === 1 && remainingPlayers === 1) || | |
remainingPlayers === 0 | |
); | |
} | |
// Our function is now much easier to understand: | |
function checkGameStatus() { | |
if (isGameLost()) { | |
quitGame(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment