Skip to content

Instantly share code, notes, and snippets.

@Genyus
Last active June 22, 2020 17:20
Show Gist options
  • Save Genyus/5e72458d2f7b9d8e002eb12f6a8e0547 to your computer and use it in GitHub Desktop.
Save Genyus/5e72458d2f7b9d8e002eb12f6a8e0547 to your computer and use it in GitHub Desktop.
JS snippet demonstrating code refactoring
function isMatch(computerChoice, playerChoice, option1, option2) {
return computerChoice === option1 && playerChoice === option2 || computerChoice === option2 && playerChoice === option1;
}
if (computer.currentChoice == player.currentChoice) {
console.log("It's a tie!");
}
else if (isMatch(computer.currentChoice, player.currentChoice, gameOptions[1], gameOptions[2]) {
console.log("Scalpellus wins!");
}
else if (isMatch(computer.currentChoice, player.currentChoice, gameOptions[0], gameOptions[2]) {
console.log("Lapis wins!");
}
else if (isMatch(computer.currentChoice, player.currentChoice, gameOptions[1], gameOptions[0]) {
console.log("Papyrus wins!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment