Skip to content

Instantly share code, notes, and snippets.

@yanzay
Created June 13, 2013 13:08
Show Gist options
  • Save yanzay/5773520 to your computer and use it in GitHub Desktop.
Save yanzay/5773520 to your computer and use it in GitHub Desktop.
def quartile(array)
return array.first if array.length <= 1
sorted = array.sort
quartile_position = 0.25 * (3 * sorted.length + 1)
quartile_int = quartile_position.to_i
lower = sorted[quartile_int - 1]
upper = sorted[quartile_int]
lower + (upper - lower) * (quartile_position - quartile_int)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment