Skip to content

Commit

Permalink
Merge pull request mouredev#6019 from BRivasTorres/main
Browse files Browse the repository at this point in the history
Reto mouredev#6 - JavaScript
  • Loading branch information
kontroldev authored Dec 9, 2023
2 parents baa8946 + b51ab3a commit 5f8ffc4
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const rules = {
"✂️": ["📄", "🦎"],
"📄": ["🗿", "🖖"],
"🗿": ["🦎", "✂️"],
"🦎": ["🖖", "📄"],
"🖖": ["✂️", "🗿"],
};

const whoWins = (arr) => {
let [p1, p2] = [0, 0]

for (const play of arr) {
let p1Play = play[0];
let p2Play = play[1];

if (p1Play === p2Play) continue;

rules[p1Play].includes(p2Play) ? p1++ : p2++
}


return p1 === p2
? "Tie"
: p1 > p2
? "Player 1"
: "Player 2";
};
console.log(
whoWins([
["🖖", "🗿"],
["✂️", "📄"],
["🗿", "🗿"],
["🦎", "🖖"],
])
);

0 comments on commit 5f8ffc4

Please sign in to comment.