Skip to content

quantileRankSorted

quantileRankSorted(x, value): number

Defined in: src/quantile_rank_sorted.js:18

This function returns the quantile in which one would find the given value in the given array. With a sorted array, leveraging binary search, we can find this information in logarithmic time.

number[]

input

number

the value for which to find the quantile rank

number

the quantile rank

if x is empty

quantileRankSorted([1, 2, 3, 4], 3); // => 0.75
quantileRankSorted([1, 2, 3, 3, 4], 3); // => 0.7
quantileRankSorted([1, 2, 3, 4], 6); // => 1
quantileRankSorted([1, 2, 3, 3, 5], 4); // => 0.8