@atlaskit/editor-plugin-ncs-step-metrics
Version:
NcsStepMetrics plugin for @atlaskit/editor-core
15 lines • 588 B
JavaScript
/**
* Calculates the 90th percentile value from an array of step sizes.
* @param stepSizeSumFor90 - An array of step sizes to calculate the 90th percentile value.
* @returns
*/
export var calculateP90Value = function calculateP90Value(stepSizeSumFor90) {
if (!stepSizeSumFor90 || (stepSizeSumFor90 === null || stepSizeSumFor90 === void 0 ? void 0 : stepSizeSumFor90.length) === 0) {
return 0;
}
var sortedSteps = stepSizeSumFor90.sort(function (a, b) {
return a - b;
});
var p90Index = Math.ceil(0.9 * sortedSteps.length) - 1;
return sortedSteps[p90Index] || 0;
};