als-statistics
Version:
Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co
17 lines (16 loc) • 798 B
JavaScript
import Stats from "../descriptive/index.js";
import { Cache } from "./cache.js";
export function addStats(Column) {
const excludes = new Set(["length", "name", "prototype"])
Object.getOwnPropertyNames(Stats).forEach(method => {
if (typeof Stats[method] !== 'function' || excludes.has(method)) return;
if (Stats[method].length === 1) Object.defineProperty(Column.prototype, method, {
get() { return this.$(method, Stats[method]) }, configurable: true, enumerable: false
})
else Object.defineProperty(Column.prototype, method, {
value: function (...params) {
return this.$(Cache.key(method, ...params), () => Stats[method](this, ...params))
}, writable: true, configurable: true, enumerable: false
})
})
}