Skip to content

Instantly share code, notes, and snippets.

@ryanmr
Created January 3, 2016 18:28
Show Gist options
  • Save ryanmr/1538928b83233fb1b6b5 to your computer and use it in GitHub Desktop.
Save ryanmr/1538928b83233fb1b6b5 to your computer and use it in GitHub Desktop.
func get_median(samples []float64) float64 {
sort.Float64s(samples)
l := len(samples)
r := 0.0
if (l % 2 == 1) {
r = samples[int(math.Floor(float64(l/2)))]
} else {
s1 := l/2
s2 := s1 + 1
r = float64((samples[s1] + samples[s2])/2.0)
}
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment