Skip to content

Instantly share code, notes, and snippets.

View yanzay's full-sized avatar

Alexey Grachov yanzay

View GitHub Profile
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