Median pivot for javascript version