This function sorts the input array and returns the number of inversions in the array
function countSwaps ( arr , n ) { let temp = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { temp [ i ] = 0 ; } return _mergeSort ( arr , temp , 0 , n - 1 ) ; }