Skip to content

Instantly share code, notes, and snippets.

@sauron
Created June 22, 2015 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauron/b577efb8693903bdf8b9 to your computer and use it in GitHub Desktop.
Save sauron/b577efb8693903bdf8b9 to your computer and use it in GitHub Desktop.
Median calculation for a given Array in Ruby
def median(array)
sorted = array.sort
len = sorted.length
return (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment