Counting inversions in JS.