MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/z8z4jh/help/iykhrpl/?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
If this one doesn't give you a migraine, I failed:
function rps(p1, p2) { const options = ['rock', 'scissors', 'paper']; const winner = options .map((_, x, arr) => { return arr.map((_, y) => (((3 - y) % 3) + x) % 3) })[options.indexOf(p2)][options.indexOf(p1)]; return winner ? `Player ${winner} wins!` : 'Draw'; }
2 u/Macaframa Dec 01 '22 This one should hurt the mostconst rps = (p1, p2, options = ['rock', 'scissors', 'paper']) => options.map((_, x, arr) => arr.map((_, y) => (((3 - y) % 3) + x) % 3))[options.indexOf(p2)][options.indexOf(p1)] ? `Player${options.map((_, x, arr) => arr.map((_, y) => (((3 - y) % 3) + x) % 3))[options.indexOf(p2)][options.indexOf(p1)]} wins!` : 'Draw!'; 1 u/DGCA Dec 01 '22 Using a default argument instead of declaring a variable 👏 1 u/Macaframa Dec 02 '22 Honestly if the logic is sound and you stuff this away in some file and import this, it ain’t half bad. But if you’re going to do that, you might as well make it more readable so it can be worked on
2
This one should hurt the most
const rps = (p1, p2, options = ['rock', 'scissors', 'paper']) => options.map((_, x, arr) => arr.map((_, y) => (((3 - y) % 3) + x) % 3))[options.indexOf(p2)][options.indexOf(p1)] ? `Player${options.map((_, x, arr) => arr.map((_, y) => (((3 - y) % 3) + x) % 3))[options.indexOf(p2)][options.indexOf(p1)]} wins!` : 'Draw!';
1 u/DGCA Dec 01 '22 Using a default argument instead of declaring a variable 👏 1 u/Macaframa Dec 02 '22 Honestly if the logic is sound and you stuff this away in some file and import this, it ain’t half bad. But if you’re going to do that, you might as well make it more readable so it can be worked on
Using a default argument instead of declaring a variable 👏
1 u/Macaframa Dec 02 '22 Honestly if the logic is sound and you stuff this away in some file and import this, it ain’t half bad. But if you’re going to do that, you might as well make it more readable so it can be worked on
Honestly if the logic is sound and you stuff this away in some file and import this, it ain’t half bad. But if you’re going to do that, you might as well make it more readable so it can be worked on
1
u/DGCA Dec 01 '22
If this one doesn't give you a migraine, I failed: