Skip to content

Instantly share code, notes, and snippets.

@tarynsauer
Created June 30, 2013 01:54
Show Gist options
  • Save tarynsauer/5893466 to your computer and use it in GitHub Desktop.
Save tarynsauer/5893466 to your computer and use it in GitHub Desktop.
Calculating the median of an array of numbers
def median(array)
array.sort
if array.length%2 == 0
(array[array.length/2 - 1] + array[array.length/2])/2.0
else
array[array.length/2]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment