Find index of an extra element present in one sorted array | Function to find Index ; Calculating extra element ; returns index of extra element ; function return sum of array elements ; function return index of given element ; Driver Code
function find_extra_element_index ( arrA , arrB ) { let extra_element = sum ( arrA ) - sum ( arrB ) ; return indexOf ( arrA , extra_element ) ; } function sum ( arr ) { let sum = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { sum += arr [ i ] ; } return sum ; } function indexOf ( arr , element ) { for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == element ) { return i ; } } return - 1 ; } let arrA = [ 2 , 4 , 6 , 8 , 10 , 12 , 13 ] ; let arrB = [ 2 , 4 , 6 , 8 , 10 , 12 ] ; document . write ( find_extra_element_index ( arrA , arrB ) ) ;