Last active
June 27, 2017 15:46
-
-
Save jamesseanwright/6e4c40e16ff62925744b to your computer and use it in GitHub Desktop.
A n00b's attempt at JavaScript code golf...
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
/* uncompressed - 430 bytes | |
* minified (UglifyJS) - 273 bytes | |
* FYI - indented using tabs because one character vs 4, yo. | |
* Append ?ts = 4 to URL to format this correctly. | |
*/ | |
function p() { | |
var a, b, | |
m = Math, | |
r = m.random, | |
f = m.floor, | |
n = { | |
r: 'rock', | |
p: 'paper', | |
s: 'scissors' | |
}, | |
d = [ | |
{ n: 'r', b: 's', l: 'p' }, | |
{ n: 'p', b: 'r', l: 's' }, | |
{ n: 's', b: 'p', l: 'r' } | |
], | |
c = d.length, | |
w, l; | |
a = d[f(r() * c)]; | |
while (!b || b === a) b = d[f(r() * c)]; | |
w = a.b === b.n ? a : b; | |
l = w === a ? b : a; | |
console.log(n[w.n] + ' beats ' + n[l.n]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment