diff --git a/Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/EdGonzz.js b/Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/EdGonzz.js new file mode 100644 index 0000000000..f7f5cfa88e --- /dev/null +++ b/Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/EdGonzz.js @@ -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([["πŸ––", "🦎"], ["πŸ—Ώ", "βœ‚οΈ"], ["🦎", "βœ‚οΈ"]]))