Change in Median of given array after deleting given elements | Function to find the median change after removing elements from arr2 [ ] ; To store the median ; If N is odd ; If N is even ; Find the current element in arr1 ; Erase the element ; Decrement N ; If N is odd ; If N is even ; Print the corresponding difference of median ; Given arrays ; Function Call
function medianChange ( arr1 , arr2 ) { let N = arr1 . length ; let median = [ ] ; if ( ( N & 1 ) ) median . push ( ( arr1 [ Math . floor ( N / 2 ) ] * 1 ) ) ; else median . push ( Math . floor ( ( arr1 [ Math . floor ( N / 2 ) ] + arr1 [ Math . floor ( ( N - 1 ) / 2 ) ] ) / 2 ) ) ; for ( let x = 0 ; x < arr2 . length ; x ++ ) { let it = arr1 . indexOf ( arr2 [ x ] ) ; arr1 . splice ( it , 1 ) ; N -- ; if ( ( N & 1 ) ) { median . push ( arr1 [ Math . floor ( N / 2 ) ] * 1 ) ; } else { median . push ( Math . floor ( ( arr1 [ Math . floor ( N / 2 ) ] + arr1 [ Math . floor ( ( N - 1 ) / 2 ) ] ) / 2 ) ) ; } } for ( let i = 0 ; i < median . length - 1 ; i ++ ) { document . write ( ( median [ i + 1 ] - median [ i ] ) + " " ) ; } } let arr1 = [ 2 , 4 , 6 , 8 , 10 ] ; let arr2 = [ 4 , 6 ] ; medianChange ( arr1 , arr2 )