Using an array through a switch() statement in Javascript

前端 未结 6 2089
野的像风
野的像风 2021-01-01 23:28

I\'m trying to develop a simplified poker game through Javascript. I\'ve listed all possible card combinations a given player might have in its hand ordered by its value, li

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-02 00:12

    That will not quite work as you have it, but you can use sortedHand.join(',') and compare it with [1,1,1,2,5].join(',') which will compare the two arrays and should be true if their contents were the exact same (Be careful with numbers typed as strings!) To be fair, though, I can't imagine why you would design your logic like that. Even a simple card game has hundreds of thousands of possible hands. You might do better using underscore.js's collection managing functions as it will be simpler, and just a better practice.

提交回复
热议问题