Equivalent of d3.medianIndex

I am trying to use d3.medianIndex but I can’t cause it seems the type is missing from @types/d3.

Meanwhile, are these two equivalent? if yes, I will swap in the prod.

const medianXOne = array[d3.medianIndex(array)];
const medianXTwo = array[d3.bisectLeft(array, d3.median(array)) - 1];

Thank you in advance.
@Fil

No they’re not equivalent (just try with array=[1, 2, 3]). If you’re using d3.medianIndex please make sure you’re requiring the latest version Release v3.2.4 · d3/d3-array · GitHub. I’d suggest you add the type manually until Declaration of medianIndex is missing in [@types/d3-array] · DefinitelyTyped/DefinitelyTyped · Discussion #65706 · GitHub.

1 Like

Thanks for the confirmation, looking forward to medianIndex type getting added to @types/d3.