fix weighted median calculation to sort arrays by median value