Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created October 9, 2019 17:03
Show Gist options
  • Save NyaGarcia/4f93b44dcee6980d113413c2efc681a6 to your computer and use it in GitHub Desktop.
Save NyaGarcia/4f93b44dcee6980d113413c2efc681a6 to your computer and use it in GitHub Desktop.
Extracting a conditional to a function
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