summaryrefslogtreecommitdiff
path: root/pbt/ts/src/stats.ts
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2026-09-02 22:27:04 +0200
committerArnaud Bailly <arnaud@pankzsoft.com>2026-09-02 22:27:04 +0200
commitd68fdea59aaf05877438bfba669c96d716523765 (patch)
tree17913de3ed05cbc494b44b4ffabece46608c89f0 /pbt/ts/src/stats.ts
parent7f69074b259f479b05777ba915a6ef3481a749af (diff)
downloadlambda-nantes-main.tar.gz
Refactor generators to use a factory for passing bytesHEADmain
Diffstat (limited to 'pbt/ts/src/stats.ts')
-rw-r--r--pbt/ts/src/stats.ts10
1 files changed, 3 insertions, 7 deletions
diff --git a/pbt/ts/src/stats.ts b/pbt/ts/src/stats.ts
index 8c50856..8f9832c 100644
--- a/pbt/ts/src/stats.ts
+++ b/pbt/ts/src/stats.ts
@@ -86,15 +86,11 @@ export function chiSquare (samples : number [], expected : number []) : number {
throw new Error("Samples and expected arrays must have the same length.");
}
- let chiSquareValue = 0;
- for (let i = 0; i < samples.length; i++) {
- const observed = samples[i];
+ return samples.reduce((acc, observed, i) => {
const exp = expected[i];
if (exp === 0) {
throw new Error("Expected frequency cannot be zero.");
}
- chiSquareValue += Math.pow(observed - exp, 2) / exp;
- }
-
- return chiSquareValue;
+ return acc + Math.pow(observed - exp, 2) / exp;
+ }, 0);
}