function quantile(x, p) {
    const copy = x.slice();

    if (Array.isArray(p)) {
        // rearrange elements so that each element corresponding to a requested
        // quantile is on a place it would be if the array was fully sorted
        multiQuantileSelect(copy, p);
        // Initialize the result array
        const results = [];
        // For each requested quantile
        for (let i = 0; i < p.length; i++) {
            results[i] = quantileSorted(copy, p[i]);
        }
        return results;
    } else {
        const idx = quantileIndex(copy.length, p);
        quantileSelect(copy, idx, 0, copy.length - 1);
        return quantileSorted(copy, p);
    }
}
The [quantile](https://en.wikipedia.org/wiki/Quantile):
this is a population quantile, since we assume to know the entire
dataset in this library. This is an implementation of the
[Quantiles of a Population](http://en.wikipedia.org/wiki/Quantile#Quantiles_of_a_population)
algorithm from wikipedia.

Sample is a one-dimensional array of numbers,
and p is either a decimal number from 0 to 1 or an array of decimal
numbers from 0 to 1.
In terms of a k/q quantile, p = k/q - it's just dealing with fractions or dealing
with decimal values.
When p is an array, the result of the function is also an array containing the appropriate
quantiles in input order

@param {Array<number>} x sample of one or more numbers
@param {Array<number> | number} p the desired quantile, as a number between 0 and 1
@returns {number} quantile
@example
quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], 0.5); // => 9