Created
October 16, 2018 22:45
-
-
Save davidmfoley/d142120b6b018d76a6167962b19935e8 to your computer and use it in GitHub Desktop.
RPS in JS
This file contains hidden or 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
const precedence = ['rock', 'scissors', 'paper']; | |
const results=['TIE', 'FIRST_PLAYER', 'SECOND_PLAYER']; | |
const ordinal = x => precedence.indexOf(x); | |
const circularDirection = (a, b) => (ordinal(b) - ordinal(a) + 3) % 3; | |
const rps = (a, b) => results[circularDirection(a, b)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment