@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
14 lines • 422 B
JavaScript
export const percentile = (input, fraction) => {
const sorted = input.sort((a, b) => a - b);
const position = sorted.length * fraction;
const base = Math.floor(position);
const rest = position - base;
if (rest > 0) {
return sorted[base];
}
const item = sorted[base - 1];
const next = sorted[base];
if (typeof item !== 'undefined' && typeof next !== 'undefined') {
return (item + next) / 2;
}
};