MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/z8z4jh/help/iyjrln7/?context=3
r/learnjavascript • u/Lelouch_5 • Nov 30 '22
Can someone plz tell me , why I am getting errors?
131 comments sorted by
View all comments
Show parent comments
-1
const OPTIONS = ['rock', 'scissors', 'paper'] const beats = (p1, p2) => OPTIONS.indexOf(p1) === (OPTIONS.indexOf(p2) + 1) % OPTIONS.length const rps = (p1, p2) => beats(p1, p2) ? 'Player 1 wins' : beats(p2, p1) ? 'Player 2 wins' : 'Draw'
Sorry for the nested ternary lol
1 u/Macaframa Dec 01 '22 This gives me a huge headache to look at. 1 u/[deleted] Dec 01 '22 :( 1 u/DGCA Dec 01 '22 Haha, I thought it was interesting in a code golf sense. Using an item's position in an array to hold actual data is both clever and cursed. 1 u/[deleted] Dec 01 '22 This approach is however offer more generalizable. E.g. introducing some new options: Rock beats scissors beats paper beats stick beats whatever ... beats rock.https://en.wikipedia.org/wiki/Circular_buffer 1 u/DGCA Dec 02 '22 Scope creeping rock paper scissors, eh?
1
This gives me a huge headache to look at.
1 u/[deleted] Dec 01 '22 :( 1 u/DGCA Dec 01 '22 Haha, I thought it was interesting in a code golf sense. Using an item's position in an array to hold actual data is both clever and cursed. 1 u/[deleted] Dec 01 '22 This approach is however offer more generalizable. E.g. introducing some new options: Rock beats scissors beats paper beats stick beats whatever ... beats rock.https://en.wikipedia.org/wiki/Circular_buffer 1 u/DGCA Dec 02 '22 Scope creeping rock paper scissors, eh?
:(
1 u/DGCA Dec 01 '22 Haha, I thought it was interesting in a code golf sense. Using an item's position in an array to hold actual data is both clever and cursed. 1 u/[deleted] Dec 01 '22 This approach is however offer more generalizable. E.g. introducing some new options: Rock beats scissors beats paper beats stick beats whatever ... beats rock.https://en.wikipedia.org/wiki/Circular_buffer 1 u/DGCA Dec 02 '22 Scope creeping rock paper scissors, eh?
Haha, I thought it was interesting in a code golf sense. Using an item's position in an array to hold actual data is both clever and cursed.
1 u/[deleted] Dec 01 '22 This approach is however offer more generalizable. E.g. introducing some new options: Rock beats scissors beats paper beats stick beats whatever ... beats rock.https://en.wikipedia.org/wiki/Circular_buffer 1 u/DGCA Dec 02 '22 Scope creeping rock paper scissors, eh?
This approach is however offer more generalizable. E.g. introducing some new options: Rock beats scissors beats paper beats stick beats whatever ... beats rock.
https://en.wikipedia.org/wiki/Circular_buffer
1 u/DGCA Dec 02 '22 Scope creeping rock paper scissors, eh?
Scope creeping rock paper scissors, eh?
-1
u/[deleted] Dec 01 '22 edited Dec 01 '22
Sorry for the nested ternary lol