A JavaScript implementation of descriptive, regression, and inference statistics
—
Basic array operations for finding extremes, sums, and products.
import {
min, max, extent,
minSorted, maxSorted, extentSorted,
sum, sumSimple, product
} from "simple-statistics";/**
* Finds the minimum value in an array
* @param values - Array of numeric values
* @returns The minimum value
*/
function min(values: number[]): number;Usage Example:
import { min } from "simple-statistics";
const data = [3, 1, 4, 1, 5, 9, 2, 6];
const minimum = min(data); // 1/**
* Finds the maximum value in an array
* @param values - Array of numeric values
* @returns The maximum value
*/
function max(values: number[]): number;/**
* Finds both minimum and maximum values in one pass
* @param values - Array of numeric values
* @returns Tuple containing [min, max]
*/
function extent(values: number[]): [number, number];Usage Example:
import { extent } from "simple-statistics";
const data = [3, 1, 4, 1, 5, 9, 2, 6];
const [minimum, maximum] = extent(data); // [1, 9]/**
* Finds minimum value in a pre-sorted array (optimized)
* @param values - Pre-sorted array of numeric values
* @returns The minimum value (first element)
*/
function minSorted(values: number[]): number;/**
* Finds maximum value in a pre-sorted array (optimized)
* @param values - Pre-sorted array of numeric values
* @returns The maximum value (last element)
*/
function maxSorted(values: number[]): number;/**
* Finds extent in a pre-sorted array (optimized)
* @param values - Pre-sorted array of numeric values
* @returns Tuple containing [min, max]
*/
function extentSorted(values: number[]): [number, number];/**
* Calculates the sum of array values using Kahan summation for numerical stability
* @param values - Array of numeric values
* @returns The sum of all values
*/
function sum(values: number[]): number;Usage Example:
import { sum } from "simple-statistics";
const data = [1, 2, 3, 4, 5];
const total = sum(data); // 15/**
* Calculates the sum using simple addition (faster but less numerically stable)
* @param values - Array of numeric values
* @returns The sum of all values
*/
function sumSimple(values: number[]): number;/**
* Calculates the product of all values in an array
* @param values - Array of numeric values
* @returns The product of all values
*/
function product(values: number[]): number;Usage Example:
import { product } from "simple-statistics";
const data = [2, 3, 4];
const result = product(data); // 24Install with Tessl CLI
npx tessl i tessl/npm-simple-statistics