Ad
  • Custom User Avatar

    Smart move. I like the addition of the beatmap. That would definitely have helped cleanup my solution. It's more readable and cleaner

  • Custom User Avatar

    This solution basically looks at each component and looks at what it can beat. If the component's strength (it can beat it) is the same as the other input component, it will win.

    First it checks if the strings are the same, if they are, then return "Draw!"

    rps("rock", "rock")
    "rock" == "rock" THEN return "DRAW!"
    

    The second part looks at the hash (dictionary or object) and the key is the item and the component it can beat is the value. It does this by getting the value of the key given.

    rps("rock", "scissors")
    
    beatmap[p1]
    beatmap["rock"]  --->  "scissors"
    
    "scissors" == p2
    "scissors" == "scissors"
    
    THEN return "Player 1 won!"
    
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution