d3.medianIndex returns one less than the index of the median element. For example:
penguins[d3.medianIndex(penguins, (d) => d.body_mass_g)].body_mass_g // 3600
penguins[d3.medianIndex(penguins, (d) => d.body_mass_g) + 1].body_mass_g // 4050
I don’t think this is the intended behavior, even if we were trying to chose the “lower” element in the case where the array length is even. I expect it to return the index of the median value instead.
d3.median(penguins, (d) => d.body_mass_g) // 4050
Previously #140 #159.