Find the player to last modify a string such that even number of consonants and no vowels are left in the string | Function to find a winner of the game if both the player plays optimally ; Stores the count of vowels and consonants ; Traverse the string ; Check if character is vowel ; Increment vowels count ; Otherwise increment the consonants count ; Check if Player B wins ; Check if Player A wins ; Check if Player A wins ; If game ends in a Draw ; Given string s ; Function Call
function findWinner ( s ) { var vowels_count = 0 , consonants_count = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] === " " s [ i ] === " " s [ i ] === " " s [ i ] === " " s [ i ] === " " ) { vowels_count ++ ; } else { consonants_count ++ ; } } if ( vowels_count === 0 ) { if ( consonants_count % 2 === 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } else if ( vowels_count === 1 && consonants_count % 2 !== 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var s = " " ; findWinner ( s ) ;