Find the element that appears once in an array where every other element appears twice | function which find number ; applying the formula . ; Driver code
function singleNumber ( nums , n ) { let m = new Map ( ) ; let sum1 = 0 , sum2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! m . has ( nums [ i ] ) ) { sum1 += nums [ i ] ; m . set ( nums [ i ] , 1 ) ; } sum2 += nums [ i ] ; } return ( 2 * ( sum1 ) - sum2 ) ; } let a = [ 2 , 3 , 5 , 4 , 5 , 3 , 4 ] ; let n = 7 ; document . write ( singleNumber ( a , n ) + " " ) ; let b = [ 15 , 18 , 16 , 18 , 16 , 15 , 89 ] ; document . write ( singleNumber ( b , n ) ) ;