Winner in the Rock | Function to return the winner of the game ; Both the players chose to play the same move ; Player A wins the game ; Function to perform the queries ; Driver code
function winner ( moves ) { let data = new Map ( ) ; data . set ( ' ' , 0 ) ; data . set ( ' ' , 1 ) ; data . set ( ' ' , 2 ) ; if ( moves [ 0 ] == moves [ 1 ] ) { return " " ; } if ( ( ( data . get ( moves [ 0 ] ) | 1 << ( 2 ) ) - ( data . get ( moves [ 1 ] ) | 0 << ( 2 ) ) ) % 3 != 0 ) { return " " ; } return " " ; } function performQueries ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( winner ( arr [ i ] ) + " " ) ; } let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; performQueries ( arr , n ) ;