Check if characters of a given string can be rearranged to form a palindrome | JavaScript implementation of the above approach ; Bitvector to store the record of which character appear odd and even number of times ; Driver Code
function canFormPalindrome ( a ) { var bitvector = 0 , mask = 0 ; for ( var i = 0 ; i < a . length ; i ++ ) { var x = a . charCodeAt ( i ) - 97 ; mask = 1 << x ; bitvector = bitvector ^ mask ; } return ( ( bitvector & ( bitvector - 1 ) ) == 0 ) ; } if ( canFormPalindrome ( " " ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;