Calculating the median of an array of numbers