forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mouredev#5911 from EdGonzz/main
Reto mouredev#6 - JavaScript
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/EdGonzz.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// * Crea un programa que calcule quien gana más partidas al piedra, | ||
// * papel, tijera, lagarto, spock. | ||
// * - El resultado puede ser: "Player 1", "Player 2", "Tie" (empate) | ||
// * - La función recibe un listado que contiene pares, representando cada jugada. | ||
// * - El par puede contener combinaciones de "🗿" (piedra), "📄" (papel), | ||
// * "✂️" (tijera), "🦎" (lagarto) o "🖖" (spock). | ||
// * - Ejemplo. Entrada: [("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")]. Resultado: "Player 2". | ||
// * - Debes buscar información sobre cómo se juega con estas 5 posibilidades. | ||
|
||
const rules = { | ||
"🦎": ["🖖", "📄"], | ||
"🗿": ["🦎", "✂️"], | ||
"✂️": ["📄", "🦎"], | ||
"🖖": ["✂️", "🗿"], | ||
"📄": ["🗿", "🖖"] | ||
} | ||
|
||
const rockPaperScissorsLizardSpock = (games) => { | ||
|
||
let player1 = 0 | ||
let player2 = 0 | ||
|
||
for (const game of games) { | ||
let player1_game = game[0] | ||
let player2_game = game[1] | ||
|
||
if (player1_game !== player2_game) { | ||
if (rules[player1_game].includes(player2_game)) { | ||
player1++ | ||
} else if (rules[player2_game].includes(player1_game)) { | ||
player2++ | ||
} | ||
} | ||
} | ||
return (player1 === player2) ? 'Tie' : (player1 > player2) ? 'Player 1 Win' : 'Player 2 Win' | ||
} | ||
|
||
console.log(rockPaperScissorsLizardSpock([["🦎", "📄"], ["📄", "🖖"], ["📄", "✂️"]])) | ||
console.log(rockPaperScissorsLizardSpock([["✂️", "🖖"], ["🖖", "✂️"], ["✂️", "🦎"]])) | ||
console.log(rockPaperScissorsLizardSpock([["📄", "✂️"], ["📄", "📄"], ["🖖", "✂️"]])) | ||
console.log(rockPaperScissorsLizardSpock([["🖖", "🦎"], ["🗿", "✂️"], ["🦎", "✂️"]])) |