Find the player who is the last to remove any character from the beginning of a Binary String | Function to find the player who loses the game ; Moves for the first player ; Moves for the second player ; Iterate over array of Strings ; Check if the first and last character are the same ; Check if String start and end with character '0' ; If first player have less moves ; Given array of Strings ; Function Call
function findPlayer ( str , n ) { let move_first = 0 ; let move_sec = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] [ 0 ] == str [ i ] [ str [ i ] . length - 1 ] ) { if ( str [ i ] [ 0 ] == 48 ) move_first ++ ; else move_sec ++ ; } } if ( move_first <= move_sec ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let str = [ " " , " " ] ; let N = str [ 0 ] . length ; findPlayer ( str , N ) ;