src/analysis.js
function percentRank(arr, v) {
    if (typeof v !== 'number') throw new TypeError('v must be a number');
    for (var i = 0, l = arr.length; i < l; i++) {
        if (v <= arr[i]) {
            while (i < l && v === arr[i]) {
                i++;
            }
            if (i === 0) return 0;
            if (v !== arr[i-1]) {
                i += (v - arr[i-1]) / (arr[i] - arr[i-1]);
            }
            return i / l;
        }
    }
    return 1;
}
function percentRank(arr, v) {
    if (typeof v !== 'number') throw new TypeError('v must be a number');
    for (var i = 0, l = arr.length; i < l; i++) {
        if (v <= arr[i]) {
            while (i < l && v === arr[i]) {
                i++;
            }
            if (i === 0) return 0;
            if (v !== arr[i-1]) {
                i += (v - arr[i-1]) / (arr[i] - arr[i-1]);
            }
            return i / l;
        }
    }
    return 1;
}
function percentRank ( arr , v ) { if ( typeof v !== 'number' ) throw new TypeError ( 'v must be a number' ) ; for ( var i = 0 , l = arr . length ; i < l ; i ++ ) { if ( v <= arr [ i ] ) { while ( i < l && v === arr [ i ] ) { i ++ ; } if ( i === 0 ) return 0 ; if ( v !== arr [ i - 1 ] ) { i += ( v - arr [ i - 1 ] ) / ( arr [ i ] - arr [ i - 1 ] ) ; } return i / l ; } } return 1 ; }
Returns the percentile of the given value in a sorted numeric array.

@param {Number[]} arr
A sorted numeric array to examine.
@param {Number} v
The value at which to return the percentile.

@return {Number}
The percentile at the given value in the given array.
Returns the percentile of the given value in a sorted numeric array .