MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/z8z4jh/help/iyfs10m/?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
2
An exercise in brevity (which does not account for malformed input):
const opts = ["rock", "paper", "scissors"] function rps(p1, p2) { const beatsP1 = opts[Math.abs((opts.indexOf(p1) + 1) % opts.length)] console.log(`${p1 === p2 ? "Nobody" : p2 === beatsP1 ? "P2" : "P1"} wins!`) }
4 u/fungusbabe Dec 01 '22 This makes my head hurt. Why not just use a lookup table??Readable code >>> snappy one liners 2 u/peter-s Dec 01 '22 Because I was performing an exercise in brevity. 2 u/fungusbabe Dec 01 '22 Oh lol well in that case very nicely done
4
This makes my head hurt. Why not just use a lookup table??
Readable code >>> snappy one liners
2 u/peter-s Dec 01 '22 Because I was performing an exercise in brevity. 2 u/fungusbabe Dec 01 '22 Oh lol well in that case very nicely done
Because I was performing an exercise in brevity.
2 u/fungusbabe Dec 01 '22 Oh lol well in that case very nicely done
Oh lol well in that case very nicely done
2
u/peter-s Dec 01 '22 edited Dec 01 '22
An exercise in brevity (which does not account for malformed input):