_util.js 642 B

123456789101112131415161718192021
  1. import { createRequire } from 'node:module';
  2. import path from 'node:path';
  3. const astroPkgPath = createRequire(import.meta.url).resolve('astro/package.json');
  4. export const astroBin = path.resolve(astroPkgPath, '../astro.js');
  5. /** @typedef {{ avg: number, stdev: number, max: number }} Stat */
  6. /**
  7. * @param {number[]} numbers
  8. * @returns {Stat}
  9. */
  10. export function calculateStat(numbers) {
  11. const avg = numbers.reduce((a, b) => a + b, 0) / numbers.length;
  12. const stdev = Math.sqrt(
  13. numbers.map((x) => Math.pow(x - avg, 2)).reduce((a, b) => a + b, 0) / numbers.length
  14. );
  15. const max = Math.max(...numbers);
  16. return { avg, stdev, max };
  17. }