inversion counting algo in js