Get the median value : Math extensions « Development « Ruby






Get the median value


def median(x)
  sorted = x.sort
  mid = x.size/2
  sorted[mid]
end

data =[7,7,7,4,4,5,4,5,7,2,2,3,3,7,3,4 ]
puts median(data)  # 4

 








Related examples in the same category

1.Add function to Math module
2.Your own math function
3.Get mean value
4.Get hmean value
5.Return the gmean value
6.Get the mode value
7.Get variance value
8.Get sigma value