text: Remove odd frequency characters from the string | Function to remove the characters which have odd frequencies in the string ; Create a map to store the frequency of each character ; To store the new string ; Remove the characters which have odd frequencies ; If the character has odd frequency then skip ; Else concatenate the character to the new string ; Return the modified string ; Driver code ; Remove the characters which have odd frequencies
code: function removeOddFrequencyCharacters ( s ) { let m = new Map ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { let p = s [ i ] ; let count = m . get ( p ) ; if ( count == null ) { count = 0 ; m . set ( p , 1 ) ; } else m . set ( p , count + 1 ) ; } let new_string = " " ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( ( m . get ( s [ i ] ) & 1 ) == 1 ) continue ; new_string += s [ i ] ; } return new_string ; } let str = " " ; str = removeOddFrequencyCharacters ( str ) ; document . write ( str ) ;