2023-08-25 13:00:51 +00:00
|
|
|
import { createRequire } from 'node:module';
|
|
|
|
import path from 'node:path';
|
2023-03-01 08:46:06 +00:00
|
|
|
|
2023-08-25 13:00:51 +00:00
|
|
|
const astroPkgPath = createRequire(import.meta.url).resolve('astro/package.json');
|
|
|
|
|
|
|
|
export const astroBin = path.resolve(astroPkgPath, '../astro.js');
|
2023-07-10 15:43:01 +00:00
|
|
|
|
|
|
|
/** @typedef {{ avg: number, stdev: number, max: number }} Stat */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number[]} numbers
|
|
|
|
* @returns {Stat}
|
|
|
|
*/
|
|
|
|
export function calculateStat(numbers) {
|
|
|
|
const avg = numbers.reduce((a, b) => a + b, 0) / numbers.length;
|
|
|
|
const stdev = Math.sqrt(
|
|
|
|
numbers.map((x) => Math.pow(x - avg, 2)).reduce((a, b) => a + b, 0) / numbers.length
|
|
|
|
);
|
|
|
|
const max = Math.max(...numbers);
|
|
|
|
return { avg, stdev, max };
|
|
|
|
}
|