Find the element that appears once in an array where every other element appears twice | singleelement function ; Driver code
function singleelement ( arr , n ) { let low = 0 , high = n - 2 ; let mid ; while ( low <= high ) { mid = ( low + high ) / 2 ; if ( arr [ mid ] == arr [ mid ^ 1 ] ) { low = mid + 1 ; } else { high = mid - 1 ; } } return arr [ low ] ; } let arr = [ 2 , 3 , 5 , 4 , 5 , 3 , 4 ] ; let size = arr . length ; document . write ( singleelement ( arr , size ) ) ;